我们是否有任何通用函数来检查 Selenium 中的页面是否已完全加载?
您正在尝试确定网页是否已完全加载使用 Selenium 完成加载。尽管您已尝试使用该代码,但即使页面正在加载,它也不会等待。您寻求一种通用的解决方案,而不是检查特定元素的可见性或可点击性的解决方案。
答案:
不,没有通用的 Selenium 方法来确认完全加载网页page.
说明:
让我们检查一下您的代码:
new WebDriverWait(firefoxDriver, pageLoadTimeout).until( webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
此代码中的 pageLoadTimeout 变量实际上并不对应于真实的 pageLoadTimeout () 函数。
但是,对于检查页面是否完全加载后,您可以使用 DesiredCapability 或 ChromeOptions 类将 pageLoadStrategy() 设置为“正常”(其他可能的值包括“none”和“eager”)。以下是示例:
使用所需功能:
DesiredCapabilities dcap = new DesiredCapabilities(); dcap.setCapability("pageLoadStrategy", "normal"); FirefoxOptions opt = new FirefoxOptions(); opt.merge(dcap); WebDriver driver = new FirefoxDriver(opt);
使用ChromeOptions:
ChromeOptions opt = new ChromeOptions(); opt.setPageLoadStrategy(PageLoadStrategy.NORMAL); WebDriver driver = new FirefoxDriver(opt);
注意事项:
将 PageLoadStrategy 设置为“正常”可确保浏览器客户端已达到 'document.readyState' 等于的状态“完全的。”但是,这并不能保证所有 JavaScript 和 Ajax 调用都已完成。
要解决此问题,您可以使用函数来等待所有 JavaScript 和 Ajax 调用完成:
public void WaitForAjax2Complete() throws InterruptedException { while (true) { if ((Boolean) ((JavascriptExecutor)driver).executeScript("return jQuery.active == 0")){ break; } Thread.sleep(100); } }
或者,您可以将 WebDriverWait 与 ExpectedConditions 结合使用来等待特定事件或元素状态:
// Wait for a specific part of the page title new WebDriverWait(driver, 10).until(ExpectedConditions.titleContains("partial_title_of_application_under_test")); // Wait for a specific element to become visible WebElement ele = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("xpath_of_the_desired_element")));
参考:
- [Selenium IE WebDriver 仅适用于调试](https://stackoverflow.com/questions/23791841/selenium-ie-webdriver-only-works-while-debugging)
- [Selenium 如何管理等待页面加载?](https://stackoverflow.com/questions/19750811/selenium-how-to-manage-wait-for-page-load)
- [Chrome 的页面加载策略驱动程序](https://stackoverflow.com/questions/55985139/page-load-strategy-for-chrome-driver-updated-till-selenium-v3-12-0)
以上是是否有通用的 Selenium 函数来验证完整的网页加载?的详细内容。更多信息请关注PHP中文网其他相关文章!

JVM'SperformanceIsCompetitiveWithOtherRuntimes,operingabalanceOfspeed,安全性和生产性。1)JVMUSESJITCOMPILATIONFORDYNAMICOPTIMIZAIZATIONS.2)c提供NativePernativePerformanceButlanceButlactsjvm'ssafetyFeatures.3)

JavaachievesPlatFormIndependencEthroughTheJavavIrtualMachine(JVM),允许CodeTorunonAnyPlatFormWithAjvm.1)codeisscompiledIntobytecode,notmachine-specificodificcode.2)bytecodeisisteredbytheybytheybytheybythejvm,enablingcross-platerssectectectectectross-eenablingcrossectectectectectection.2)

TheJVMisanabstractcomputingmachinecrucialforrunningJavaprogramsduetoitsplatform-independentarchitecture.Itincludes:1)ClassLoaderforloadingclasses,2)RuntimeDataAreafordatastorage,3)ExecutionEnginewithInterpreter,JITCompiler,andGarbageCollectorforbytec

JVMhasacloserelationshipwiththeOSasittranslatesJavabytecodeintomachine-specificinstructions,managesmemory,andhandlesgarbagecollection.ThisrelationshipallowsJavatorunonvariousOSenvironments,butitalsopresentschallengeslikedifferentJVMbehaviorsandOS-spe

Java实现“一次编写,到处运行”通过编译成字节码并在Java虚拟机(JVM)上运行。1)编写Java代码并编译成字节码。2)字节码在任何安装了JVM的平台上运行。3)使用Java原生接口(JNI)处理平台特定功能。尽管存在挑战,如JVM一致性和平台特定库的使用,但WORA大大提高了开发效率和部署灵活性。

JavaachievesPlatFormIndependencethroughTheJavavIrtualMachine(JVM),允许Codetorunondifferentoperatingsystemsswithoutmodification.thejvmcompilesjavacodeintoplatform-interploplatform-interpectentbybyteentbytybyteentbybytecode,whatittheninternterninterpretsandectectececutesoneonthepecificos,atrafficteyos,Afferctinginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginginging

JavaispoperfulduetoitsplatFormitiondence,对象与偏见,RichstandardLibrary,PerformanceCapabilities和StrongsecurityFeatures.1)Platform-dimplighandependectionceallowsenceallowsenceallowsenceallowsencationSapplicationStornanyDevicesupportingJava.2)

Java的顶级功能包括:1)面向对象编程,支持多态性,提升代码的灵活性和可维护性;2)异常处理机制,通过try-catch-finally块提高代码的鲁棒性;3)垃圾回收,简化内存管理;4)泛型,增强类型安全性;5)ambda表达式和函数式编程,使代码更简洁和表达性强;6)丰富的标准库,提供优化过的数据结构和算法。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver Mac版
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

WebStorm Mac版
好用的JavaScript开发工具

Atom编辑器mac版下载
最流行的的开源编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中