栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何让Selenium不要等到整个页面加载后脚本运行缓慢?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何让Selenium不要等到整个页面加载后脚本运行缓慢?

当Selenium默认加载页面/ URL时,它将遵循默认配置,

pageLoadStrategy
设置为
normal
。为了使Selenium不等待整个页面加载,我们可以配置
pageLoadStrategy
pageLoadStrategy
支持3个不同的值,如下所示:

  1. normal (整页加载)
  2. eager (互动)
  3. 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")


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/431793.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号