djd97
djd97

Reputation: 77

Waiting for a page to load with Selenium

How would I select a value in a data-bind span so that I can use Selenium's wait command to wait for it to appear?

I want it to wait until the firstNum span appears.

<div class ="pagination-info">
     <span class="visiblelist">Showing</span>
     <span data-bind="number: firstNum">100</span>
     <span data-bind="number: lastNum">130</span>
</div>

Code snippet:

DRIVER = webdriver.Chrome(chrome_options=chrome_options)
DRIVER.get(url)
# wait should go here
data = DRIVER.page_source

P.s. It's a dynamic site, so I'll be on url&page=1 and go to url&page=2 and I'll need to wait for the dynamic element to load.

Upvotes: 1

Views: 325

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193358

To wait for the visibility of the <span> element with a data-bind value you can use the following block of code :

DRIVER = webdriver.Chrome(chrome_options=chrome_options)
DRIVER.get(url)
WebDriverWait(DRIVER, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='pagination-info']//span[@data-bind='number: firstNum' and contains(.,'100')]"))) 
data = DRIVER.page_source

Upvotes: 1

Related Questions