当Selenium默认加载页面/ URL时,它将遵循默认配置,
pageLoadStrategy设置为
normal。为了使Selenium不等待整个页面加载,我们可以配置
pageLoadStrategy。
pageLoadStrategy支持3个不同的值,如下所示:
- normal (整页加载)
- eager (互动)
- none
这是配置代码的代码块
pageLoadStrategy:
火狐:
from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiescaps = DesiredCapabilities().FIREFOXcaps["pageLoadStrategy"] = "normal" # complete#caps["pageLoadStrategy"] = "eager" # interactive#caps["pageLoadStrategy"] = "none"driver = webdriver.Firefox(desired_capabilities=caps, executable_path=r'C:pathtogeckodriver.exe')driver.get("http://google.com")
铬:
from selenium import webdriverfrom selenium.webdriver.common.desired_capabilities import DesiredCapabilitiescaps = DesiredCapabilities().CHROMEcaps["pageLoadStrategy"] = "normal" # complete#caps["pageLoadStrategy"] = "eager" # interactive#caps["pageLoadStrategy"] = "none"driver = webdriver.Chrome(desired_capabilities=caps, executable_path=r'C:pathtochromedriver.exe')driver.get("http://google.com")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)