gpt4 book ai didi

python - selenium.common.exceptions.TimeoutException : Message: Timed out waiting for page to load using IEDriverServer and Internet Explorer through Selenium

转载 作者:行者123 更新时间:2023-12-04 09:22:01 25 4
gpt4 key购买 nike

鉴于此代码:

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()
当我运行它时,每次尝试,在任何网站上都会返回此错误:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.
在不同的 PC 上运行相同的代码可以正常工作,在我的情况下,我希望测试失败并找不到元素,因为指定的 xpath 是错误的。
该过程“卡在”
browser.get("https://www.google.ro/?safe=active&ssui=on")
好像页面没有正确加载一样。
我正在使用 python 3.8.0
IEDriverServer_x64_3.150.1 Selenium 驱动

最佳答案

此错误消息...

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: Timed out waiting for page to load.
...意味着 IEDriverServer 可执行二进制文件无法启动/产生新的浏览上下文,即 Internet Explorer 浏览 session 。

根据 Required ConfigurationInternet Explorer Driver :
保护模式
在 Windows Vista 或 Windows 7 上的 Internet Explorer 7 或更高版本上,您必须设置 保护模式每个区域的设置为相同的值。该值可以打开或关闭,只要每个区域都相同。设置 保护模式设置 您必须从“工具”菜单中选择“Internet 选项”,然后单击“安全”选项卡。对于每个区域,标签底部都会有一个复选框,标记为 。启用保护模式 .
ProtectedModeSettings
此外, @JimEvans在他的文章中 You're Doing It Wrong: IE Protected Mode and WebDriver明确提到:

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 and IntroduceInstabilityByIgnoringProtectedModeSettings 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.



解决方案
访问网址 https://www.google.ro/?safe=active&ssui=on使用 Selenium驱动 发起 浏览上下文,您可以使用以下最小代码块:
from selenium import webdriver

driver = webdriver.Ie(executable_path=r'C:\WebDrivers\IEDriverServer.exe')
driver.get('https://www.google.ro/?safe=active&ssui=on')

其他注意事项
确保以下步骤:
  • 将 JDK 升级到当前级别 JDK 8u251 .
  • 将 Selenium 升级到当前级别 Version 3.141.59 .
  • 升级IEDriverServer到最新IEDriverServer v3.150.1等级。

  • 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.


  • 通过 IDE 清理项目工作区并仅使用所需的依赖项重建项目。
  • 执行您的 @Test .
  • 总是调用 driver.quit()tearDown(){} 内优雅地关闭和销毁 WebDriver 和 Web 客户端实例的方法。

  • 引用
    您可以在以下位置找到一些相关的详细讨论:
  • 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
  • 关于python - selenium.common.exceptions.TimeoutException : Message: Timed out waiting for page to load using IEDriverServer and Internet Explorer through Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63086747/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com