I have plain HTML text <b>text</b> on the webpage. With Selenium WebDriver, I need to make it easy to check that the text is on the webpage. I can find an element using XPath, but I don't know how to make it an assertion on it.
- 2What guides have you read on assertions? Have you googled assert libraries that are available in python and read their docs? What examples did you find? After you've done all this, if you still don't have your answer, update your question and put specifics of what you've tried and what didn't work. This site and the internet already has a TON of examples of what you are asking. There's nothing unique there.JeffC– JeffC2019-06-17 15:52:59 +00:00Commented Jun 17, 2019 at 15:52
Add a comment |
1 Answer
Python:
driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) text_tag = wait.until(EC.presence_of_element_located((By.XPATH,"the xpath to <b>text</b>"))) assert text_tag.text == "text" Hope this helps you!
4 Comments
Tomasito
Thank you, I have only next problem with this error:
assert text_tag.text() == "asdfaf" TypeError: 'str' object is not callableMoshe Slavin
@Tomasito sorry I had a typo... it should be
text_tag.text not text_tag.text() I'll edit it!Tomasito
super, now is ok. Thank you very much !!
Moshe Slavin
@Tomasito glad to help!