selenium.common.exceptions.TimeoutException:消息:超时,正在等待通过IEDriverServer和Internet Explorer通过Selenium加载页面 [英] selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load using IEDriverServer and Internet Explorer through Selenium
问题描述
给出此代码:
从硒导入Webdriver的 从selenium.webdriver.common.desired_capabilities导入DesiredCapabilities从selenium.webdriver.support.ui导入选择来自selenium.webdriver.common.by导入方式#导入org.openqa.selenium.Keys导入日期时间导入时间导入单元测试cap = DesiredCapabilities().INTERNETEXPLORERcap ['ignoreProtectedModeSettings'] = Truecap ['IntroduceInstabilityByIgnoringProtectedModeSettings'] = Truecap ['nativeEvents'] = Truecap ['ignoreZoomSetting'] = Truecap ['requireWindowFocus'] = Truecap ['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] =真浏览器= webdriver.Ie(功能=容量,executable_path = r'C:\ IEDriverServer_x64_3.150.1 \ IEDriverServer.exe')browser.get(" https://www.google.ro/?safe = active& ssui = on")search_form = browser.find_element_by_xpath('/html [1]/body [1]/div [1]/div [1]/div [3]/div [1]/button [1]')search_form.click()
当我运行它时,在任何网站上的每次尝试都会返回此错误:
引发exception_class(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:等待页面加载超时.
在另一台PC上运行相同的代码可以很好地工作,在我的情况下,由于指定的xpath错误,我希望测试失败并找不到元素.
该过程被卡住".在
browser.get(" https://www.google.ro/?safe = active& ssui = on")
好像页面无法正确加载.
我正在使用python 3.8.0IEDriverServer_x64_3.150.1硒驱动程序
此错误消息...
引发exception_class(消息,屏幕,堆栈跟踪)selenium.common.exceptions.TimeoutException:消息:等待页面加载超时.
...表示 IEDriverServer 可执行二进制文件无法启动/产生新的浏览上下文,即 Internet Explorer浏览会话./p>
按照明确提到:
使用该功能并不能解决根本问题.如果越过保护模式边界,可能会导致非常意外的行为,包括挂起,元素位置不起作用以及单击不传播.为了警告人们这个潜在的问题,此功能使用了听起来很吓人的大名称,例如 Java 中的
INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
和中的IntroduceInstabilityByIgnoringProtectedModeSettings
.NET .我们确实以为告诉用户使用此设置会在他们的代码中引入潜在的缺陷,因此会阻止其使用,但事实并非如此.
解决方案
使用硒-iedriver 的问题发起了 JDK8u251 .
注意:按照最佳实践的规定, Selenium Client 和 InternetExplorerDriver 会同步发布,您必须尝试来使用来自同一主要版本的两个二进制文件.
- 通过 IDE
- 清理您的项目工作区和重建您的项目,并且仅具有必需的依赖项.
- 执行您的
@Test
. - 始终在
tearDown(){}
方法中调用driver.quit()
以关闭&优雅地销毁 WebDriver 和 Web Client 实例.
参考文献
您可以在以下位置找到几个相关的详细讨论:
- Internet Explorer保护模式设置和缩放级别
- 如何忽略可以通过Selenium和Java使用setCapability()获得Internet Explorer的受保护模式设置?
- 如何忽略缩放设置
Given this code :
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
# import org.openqa.selenium.Keys
import datetime
import time
import unittest
cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreProtectedModeSettings'] = True
cap['IntroduceInstabilityByIgnoringProtectedModeSettings'] = True
cap['nativeEvents'] = True
cap['ignoreZoomSetting'] = True
cap['requireWindowFocus'] = True
cap['INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS'] = True
browser = webdriver.Ie(capabilities=cap, executable_path=r'C:\IEDriverServer_x64_3.150.1\IEDriverServer.exe')
browser.get("https://www.google.ro/?safe=active&ssui=on")
search_form = browser.find_element_by_xpath('/html[1]/body[1]/div[1]/div[1]/div[3]/div[1]/button[1]')
search_form.click()
When I run it, for every try, on any website this error is returned :
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.
Running the same code on a different PC works fine, in my case I want the test to fail with element not found, given the xpath specified is wrong.
The process is "stuck" at
browser.get("https://www.google.ro/?safe=active&ssui=on")
as if the page didn't load properly.
I am using python 3.8.0 IEDriverServer_x64_3.150.1 selenium driver
This error message...
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.
...implies that the IEDriverServer executable binary was unable to initiate/spawn a new Browsing Context i.e. Internet Explorer Browsing session.
As per the Required Configuration of Internet Explorer Driver:
Protected Mode
On Internet Explorer 7 or higher on Windows Vista or Windows 7, you must set the Protected Mode settings for each zone to be the same value. The value can be on or off, as long as it is the same for every zone. To set the Protected Mode settings you have to choose "Internet Options" from the "Tools" menu and then click on the Security tab. For each zone, there will be a check box at the bottom of the tab labeled Enable Protected Mode.
Additionally, @JimEvans
in his article You're Doing It Wrong: IE Protected Mode and WebDriver clearly mentions :
Using the capability doesn't solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like
INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
in Java andIntroduceInstabilityByIgnoringProtectedModeSettings
in .NET. We really thought that telling the user that using this setting would introduce potential badness in their code would discourage its use, but it turned out not to be so.
Solution
To access the url https://www.google.ro/?safe=active&ssui=on
using Selenium driven selenium-iedriver initiated internet-explorer Browsing Context you can use the following minimal code block:
from selenium import webdriver
driver = webdriver.Ie(executable_path=r'C:\WebDrivers\IEDriverServer.exe')
driver.get('https://www.google.ro/?safe=active&ssui=on')
Additional Considerations
Ensure the following steps:
- Upgrade JDK to current levels JDK 8u251.
- Upgrade Selenium to current levels Version 3.141.59.
- Upgrade IEDriverServer to latest IEDriverServer v3.150.1 level.
Note: As per best practices as Selenium Client and InternetExplorerDriver are released in sync and you must try to use both the binaries from the same major release.
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- Execute your
@Test
. - Always invoke
driver.quit()
withintearDown(){}
method to close & destroy the WebDriver and Web Client instances gracefully.
References
You can find a couple of relevant detailed discussions in:
- Internet Explorer Protective mode setting and Zoom levels
- How to ignore protected Mode Settings for Internet Explorer using setCapability() through Selenium and Java?
- How to ignore zoom setting
这篇关于selenium.common.exceptions.TimeoutException:消息:超时,正在等待通过IEDriverServer和Internet Explorer通过Selenium加载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!