python selenium - webdriver等到css_Selector可见

时间:2016-11-20 19:07:16

标签: python selenium webdriver python-3.5

text = browser.find_element_by_css_selector('.dbaListing.listing.lastListing > td:nth-child(4) > span').text

这就是我希望我的webdriver等待定位/可见的内容。 我该怎么做?

2 个答案:

答案 0 :(得分:2)

使用WebDriverWait with the visibility_of_element_located Expected Condition

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

wait = WebDriverWait(browser, 10)
element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".dbaListing.listing.lastListing > td:nth-child(4) > span")))
print(element.text)

答案 1 :(得分:0)

将一些wating时间传递给浏览器,直到CSS选择器可见(加载)。您也可以通过隐式等待函数传递或使用

 Wait.until()