Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python + Selenium: how to wait for string presence

I'm looking for data on a website with different webpages. When I move from one webpage to the other, I want to wait for the presence of a value called "location" using an implicit wait function. My code looks like this:

wait = WebDriverWait(driver, 
10).until(EC.presence_of_element_located((By.CLASS_NAME, 
"locationTitle")))

The HTML looks like this:

<div class="locationTitle">This Location</div>

Right now my code works for the first jump between page 1 and page 2. However, after the second page, the pages all have the same class 'locationTitle'. So I need to look for the page specific text that is "This Location". Do you know how?

Help would really be appreciated!

like image 357
titusAdam Avatar asked Jul 17 '26 14:07

titusAdam


1 Answers

Try to use search By.XPATH instead of By.CLASS_NAME:

wait = WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,"//div[text()='This Location']")))
like image 170
Andersson Avatar answered Jul 19 '26 02:07

Andersson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!