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.
Asked
Active
Viewed 575 times
-1

Ratmir Asanov
- 6,237
- 5
- 26
- 40

Tomasito
- 306
- 2
- 15
-
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 Jun 17 '19 at 15:52
1 Answers
2
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!

Community
- 1
- 1

Moshe Slavin
- 5,127
- 5
- 23
- 38
-
Thank you, I have only next problem with this error: `assert text_tag.text() == "asdfaf" TypeError: 'str' object is not callable` – Tomasito Jun 18 '19 at 07:31
-
@Tomasito sorry I had a typo... it should be `text_tag.text` not `text_tag.text()` I'll edit it! – Moshe Slavin Jun 18 '19 at 08:12
-
-