from selenium import webdriver
driver = webdriver.Firefox()
driver.get("https://google.com")
driver.implicitly_wait(80)
print driver.page_source.encode('utf-8')
渔获物在哪里?为什么不开放?
答案 0 :(得分:0)
您应该使用implicit_wait
driver.get
from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(10) # seconds
driver.get("http://somedomain/url_that_delays_loading")
myDynamicElement = driver.find_element_by_id("myDynamicElement")
隐式等待是告诉WebDriver在尝试查找一个或多个元素(如果它们不是立即可用)时轮询DOM一段时间。默认设置为0.设置后,将为WebDriver对象实例的生命周期设置隐式等待。
关于您在评论中的问题:
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
executable_path = "path_to_webdriver"
os.environ["webdriver.chrome.driver"] = executable_path
chrome_options = Options()
chrome_options.add_extension('path_to_extension')
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options)
driver.get("http://stackoverflow.com")
driver.quit()