titusAdam
titusAdam

Reputation: 809

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!

Upvotes: 3

Views: 1350

Answers (1)

Andersson
Andersson

Reputation: 52695

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']")))

Upvotes: 2

Related Questions