Selenium,点击元素,挂起 [英] Selenium, click on element, hangs

查看:47
本文介绍了Selenium,点击元素,挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是关于java中的selenium webdriver.如果单击一个元素,通常它会很快,但有时当服务器繁忙时,它会在浏览器顶部显示 Connecting... 并挂起.通常处理等待,代码为:driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);但是在这种情况下,当服务器挂在 click() 上时,这不会在时间限制后引发异常,因为在单击完成连接到下一个 url 之前,webdriver 不会开始计数.以前有没有人处理过这个问题,如何处理?

有没有办法计时 click()submit() 的完成时间?

解决方案

是的,这是一个已知问题,从 Selenium 2.21.0 开始,有一种方法可以解决.

问题在于隐式等待旨在在您搜索某些元素时等待已卸载的元素,但 click() 方法只会等到浏览器指出页面已完全加载.>

试试 driver.manage().timeouts().pageLoadTimeout() 这是 2.21.0 中的新方法,应该准确处理这个.

This is about selenium webdriver in java. If clicking on an element, usually it goes fast but sometimes when server is busy it will say Connecting... at the top of the browser and hang. Usually to deal with waits, the code is: driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); but in this case when the server hangs on a click(), this doesn't throw an exception after the time limit, since the webdriver does not start counting until the click finishes connecting to the next url. Did anyone deal with this before, and how?

Is there a way to time completion of click() and submit()?

解决方案

Yes, this is a known problem and as of Selenium 2.21.0, there is a way to go around.

The problem is that implicit wait is designed to wait for unloaded elements when you search for some, but the click() method just waits until the browser states that the page is fully loaded.

Try driver.manage().timeouts().pageLoadTimeout() which is a new method in 2.21.0 and should deal exactly with this.

这篇关于Selenium,点击元素,挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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