Hi I am using selenium to automate test on web pages. I am using selenium 2 and python and would like to have answers in this framework only. SO how do I check whether some text is present or not? I have tried asset equals but it is not working?
assertEquals(driver.getPageSource().contains("email"), true);
You can use
driver.page_source
and a simple regular expression to check if the text exists:You can try something like
Essentially the above lines launch Firefox, navigate to the specified url, cause the browser to hold for 10 seconds, for some url to load then look for a specific link text, if no link text is found, a TimeoutException is triggered.
Please note the number of brackets used, you will run into errors if the number of brackets does not correspond like the above.
To be able to run the above statement, the following must have been declared
This uses "element_to_be_clickable" - a full list of wait-conditions can be found here: Selenium Python: Waits
For those of you who are still interested:
Generic Solution
unittest:
pytest: