等待页面加载Selenium

时间:2018-03-04 20:33:47

标签: python-2.7 selenium selenium-webdriver webdriverwait

如何在数据绑定范围中选择一个值,以便我可以使用Selenium的wait命令等待它出现?

我希望它等到第一个跨度出现。

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

代码段:

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

P.S。它是一个动态网站,所以我将在url&amp; page = 1并转到url&amp; page = 2,我需要等待动态元素加载。

1 个答案:

答案 0 :(得分:1)

要等待具有 data-bind 值的<span>元素的可见性,您可以使用以下代码块:

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