python selenium - webdriver wait until css_Selector visible

浪尽此生 提交于 2019-12-31 05:46:05

问题


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

This is what I want my webdriver to wait for to be located/visible. How do I do that?


回答1:


Use 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)



回答2:


Pass some wating time to browser until the CSS selector is visible(loaded). You can also pass by implicitly wait function or use

 Wait.until() 


来源:https://stackoverflow.com/questions/40708200/python-selenium-webdriver-wait-until-css-selector-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!