0

I want to make a check for the appearance of text on the page that is inside The text looks something like "Constantly different nickname" + "Constantly the same text" on the same line. I tried to make it like this

s = driver.find_element(By.XPATH, "//span[text()='has joined & will be ready to chat in just a minute.']").text()
print(s)

And many more different attempts, but nothing worked I need to get the whole string when its permanent part appears on the page

1 Answer 1

1

Use expected conditions to wait until an element appears on the page. Set an appropriate amount of seconds in WebDriverWait that you think the element should appear.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 5).until(
    EC.visibility_of_element_located((By.XPATH, "//span[text()='has joined & will be ready to chat in just a minute.']"))
)

Read also the docs regarding Waits: https://selenium-python.readthedocs.io/waits.html

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

2 Comments

Use visibility here since this just checks to see if the element is there.
True as he cleary mentioned "appearence", thank you @Arundeep Chohan. I edited my answer.

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.