Selenium HtmlUnit 冻结随机加载网页
我在使用 Selenium 时遇到 HtmlUnitDriver 问题。
我使用的是 Selenium 2.5 版本。
该测试非常简单,通常可以正常工作,但有时驱动程序只是停下来并无休止地等待页面加载。
我的代码是这样的:
初始化...
private WebDriver driver;
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);((HtmlUnitDriver) driver).setJavascriptEnabled(true);
//driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
然后有很多像这样的块:
new Actions(driver).moveToElement(driver.findElement(By.linkText("Someting"))).perform();
driver.findElement(By.linkText("something else")).click();
driver.findElement(By.name("something")).sendKeys("8");
driver.findElement(By.xpath("//img[@title='something']")).click();
在每个 clic() 之后,它加载一个新页面。
我通常会正确结束整个测试,并且我尝试捕获所有块,因此网络不是问题。
网络驱动程序忽略超时(我尝试了很多不同的超时,但问题仍然存在),并且我无法阻止驱动程序调用“quit()”或“close()”的另一个线程,
我到处搜索,但找不到解决方案。
¿任何人都可以帮助我吗?
提前致谢。
im having a problem with HtmlUnitDriver using Selenium.
Im using the Selenium 2.5 version.
The test is so simply and usualy it works correctly but sometimes the driver just stop and wait endlessly for a page to load.
my code is something like this:
initialization...
private WebDriver driver;
driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6);((HtmlUnitDriver) driver).setJavascriptEnabled(true);
//driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS);
driver.manage().timeouts().setScriptTimeout(0, TimeUnit.MILLISECONDS);
and then a lot of blocks like this one:
new Actions(driver).moveToElement(driver.findElement(By.linkText("Someting"))).perform();
driver.findElement(By.linkText("something else")).click();
driver.findElement(By.name("something")).sendKeys("8");
driver.findElement(By.xpath("//img[@title='something']")).click();
after each clic() it loads a new page.
I usualy end the whole test correctly and i have try catched all the blocks so the web is not the problem.
The webdriver is ignoring the timeouts(i try a lot of diferent timeouts and the problem persists) and i cant stop the driver from another threads invoquing "quit()" or "close()"
I search everywhere but i cant found a solution.
¿Anyone can help me?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了,如果有人遇到同样的问题,我会发布我的解决方案。
我从其他线程按 esc (主要是忙着等待......),
然后我终止浏览器并重新启动测试
I solve it, i post my solution if anyone have the same problem.
Im pressing esc from other thread (the main is busy waiting...)
and then i kill the browser and restart the test
我以前遇到过这种行为。
我会首先更新到 2.9 并重试
然后,我会检查我正在访问的页面,因为如果它们有框架或 iframe,它们也会被下载,如果您不控制它们的内容,任何事情都可能发生
看看这个 < a href="https://stackoverflow.com/questions/7200886/extremely-simple-code-not-working-in-htmlunit-2-9-stable">链接,因为它可能有您的解决方案重新寻找 为了。
希望这有帮助。
I've faced this behaviour before.
I would first update to 2.9 and try again
Then, I would check the pages I'm hitting, because if they have frames or iframes they get downloaded too and if you don't control their content anything could happen
Take a look at this link because it might have the solution you're looking for.
Hope this helps.