pageLoadTimeout在Selenium中不起作用-Java [英] pageLoadTimeout is not working in Selenium - Java

查看:377
本文介绍了pageLoadTimeout在Selenium中不起作用-Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Linux主机上测试一个网站.我正在访问的页面是无限加载的,因此我尝试为硒设置pageLoadTimeout. Firefox已正确触发,但URL栏上的URL无法加载/导航/添加.只是空白的Firefox窗口.我也没有看到任何错误.

I am testing a website in linux host.The page i am accessing loads infinitely so I am trying to set pageLoadTimeout for selenium. Firefox is triggered correctly but URL is not loading/navigating/added in url bar.just blank firefox window.I am not seeing any errors also.

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);
driver.get("http://www.example.com");

但是,如果我删除了driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS);代码,效果很好

However if I remove driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.SECONDS); code is working fine

硒版本:3.14.0;

Selenium version : 3.14.0;

gecko驱动程序:18-Linux(已通过gecko 16,17测试,同样存在问题)

gecko driver : 18 - linux (tested with gecko 16,17 also same issue)

浏览器:firefox-52

browser : firefox-52

os/platform:Linux

os/platform : linux

如果出现此类问题,如何确保我的驱动程序在5分钟后退出自身.主机将仅支持firefox 52.

If this kind of some issue how do I make sure my driver quit itself after 5 minute.Host will support only firefox 52.

我检查了此链接,但没有解决我的问题.

I checked this link but doesnt fix my problem.

谢谢 Jk

推荐答案

您可以为浏览器设置页面加载策略,这将使页面不再等待其他Selenium命令的完整页面加载被执行.以下是Java中的示例代码片段.支持三个值:

You can set the pageload strategy for browser which will then make the page not wait for the full page load for your other Selenium commands to be executed. Below is the sample code snippet in Java. There are three supported values:

普通

这种状态导致Selenium等待整个页面加载(下载并解析了html内容和子资源).

This stategy causes Selenium to wait for the full page loading (html content and subresources downloaded and parsed).

渴望

这种状态导致Selenium等待DOMContentLoaded事件(仅下载和解析html内容).

This stategy causes Selenium to wait for the DOMContentLoaded event (html content downloaded and parsed only).

此策略使Selenium在完全接收初始页面内容(下载了html内容)后立即返回.

This strategy causes Selenium to return immediately after the initial page content is fully received (html content downloaded).

默认情况下,Selenium加载页面时,它遵循 normal pageLoadStrategy.

By default, when Selenium loads a page, it follows the normal pageLoadStrategy.

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("pageLoadStrategy", "eager");
FirefoxOptions opt = new FirefoxOptions();
opt.merge(caps);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com/");

如果您只对页面的HTML感兴趣,最好使用渴望"策略.

If you are interested only in the HTML of the page, better use the "eager" strategy.

这篇关于pageLoadTimeout在Selenium中不起作用-Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆