如果已加载所需元素,请使Selenium Webdriver停止加载页面? [英] Make Selenium Webdriver Stop Loading the page if the desired element is already loaded?

查看:1322
本文介绍了如果已加载所需元素,请使Selenium Webdriver停止加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建测试并遇到一些问题。这是场景。我使用Selenium Web驱动程序在Page1上填写表单,然后单击按钮提交表单。第2页开始加载...但问题是,Page2使用Google Analytics代码,有时页面停止加载需要永久。

I am creating a test and having some issues. Here is the scenario. I use Selenium Web driver to fill out a form on Page1 and submit the form by clicking a button. Page2 starts loading... but the problem is, Page2 uses Google Analytics codes, and sometimes it takes forever for the page to stop loading.

即使预期元素是已经存在,Selenium网页驱动程序在整个网页完全加载之前不会继续。

Even though the expected element is already present, Selenium web driver does not proceed until the whole web page is fully loaded.

如何让Selenium继续下一个任务或停止加载外部javascript / css如果预期元素已经存在?

How do I make Selenium to move on to the next task or stop loading external javascript/css if the expected element is already present?

我尝试调整以下设置但没有运气。

I tried tweaking the following settings but no luck.

driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

临时解决方案:向下滚动以获得答案!

TEMPORARY SOLUTION: Scroll below for answer!

推荐答案

所以,我向Selenium报告了这些问题。临时解决方法是......搞乱Firefox的超时设置。基本上默认情况下,Firefox会在您计时之前等待大约250秒。您可以查看:config以获取详细信息。基本上我把它调低了,所以Firefox不会等待太长时间,Selenium可以继续,好像页面已经完成加载:P。

So, I reported to Selenium about these issues. And the temporary workaround is... messing with Firefox's timeout settings. Basically by default Firefox waits about 250 seconds for each connection before timing you out. You can check about:config for the details. Basically I cranked it down so Firefox doesn't wait too long and Selenium can continue as if the page has already finished loading :P.

其他浏览器可能存在类似的配置。我仍然认为Selenium应该让我们处理pagetimeout异常。请务必在此处为错误添加星标: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars% 20Type%20Status%20Priority%20Milestone%20Owner%20Summary ,所以selenium修复了这些问题。

Similar config might exist for other browsers. I still think Selenium should let us handle the pagetimeout exception. Make sure you add a star to the bug here: http://code.google.com/p/selenium/issues/detail?id=6867&sort=-id&colspec=ID%20Stars%20Type%20Status%20Priority%20Milestone%20Owner%20Summary, so selenium fixes these issues.

FirefoxBinary firefox = new FirefoxBinary(new File("/path/to/firefox.exe"));
FirefoxProfile customProfile = new FirefoxProfile();
customProfile.setAcceptUntrustedCertificates(true);
customProfile.setPreference("network.http.connection-timeout", 10);
customProfile.setPreference("network.http.connection-retry-timeout", 10);

driver = new FirefoxDriver(firefox, customProfile);
driver.manage().deleteAllCookies();

这篇关于如果已加载所需元素,请使Selenium Webdriver停止加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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