3

The problem is, I can't see my print in console, although I should!

def test_123(app):
 wd = app.wd
 app.open_page("page_adress")
 time.sleep(3)
 element = wd.find_element_by_xpath("locator").text
 print(element)

String from my app file:

wd = webdriver.Chrome()

My test runs successful. And one more thing! If after my print command I'm putting some string which leads my test to the crash, I can see print with all other crash information.

2 Answers 2

2

The problem is, I can't see my print in console, although I should!

If you use behave as the launcher for the Selenium tests, you can solve this by passing --no-capture as an argument in your behave command:

behave -i  my_feature.feature --no-capture

Without this argument, outputs from print() are captured and discarded.

Sign up to request clarification or add additional context in comments.

2 Comments

What behave command are you talking about? This doesn't seem relevant to the question asked.
behave is a comand used with the Cucumber tool, this command is used to run .features scenarios in python + selenium environments. But adding the --no-option in the command line should work the same way.
0

Is there a space in the actual print call in your code or is that a typo? I know in python 3.X with Selenium I've only ever used print as follows:

print(element)

Notice there is no space between the print command and the parenthesis.

Updating

Ok so now that I've got my head on right (sorry for the idiot first response), let's take a look at the problem. First things first, when using Selenium and python, I always create a driver object to pass my handle around like so:

driver = webdriver.Chrome()

Secondly, if you happen to know the ID of the element, you can use driver.find_element_by_id('locator'). It's a bit more explicit in my opinion if you care to use it. The big thing though is the first point where you create a driver object. Try giving that a shot and let me know if it's still not working. :-)

13 Comments

Oh, unfortunately, with space and without it I have the same result (
Updated the answer above. See if that works for you.
Ok so with those changes it still isn't working for you? Also, try using by_id instead of xpath: element = wd.find_element_by_id("locator").text
I have a filling, that my print is going somewhere but not in the console. Because it appears there only with a crash information, when a made my test to crash
Assuming you set up everything correctly and are running the selenium script through command line you should be seeing your output in the same command line. Have you tried debugging the script to see specifically what line of code you are getting the error on? Also, can you post the error you are getting in your command line?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.