Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python selenium.common.exceptions.TimeoutException:消息:等待通过selenium使用IEDriverServer和Internet Explorer加载页面时超时_Python_Selenium_Selenium Webdriver_Internet Explorer_Selenium Iedriver - Fatal编程技术网

Python selenium.common.exceptions.TimeoutException:消息:等待通过selenium使用IEDriverServer和Internet Explorer加载页面时超时

Python selenium.common.exceptions.TimeoutException:消息:等待通过selenium使用IEDriverServer和Internet Explorer加载页面时超时,python,selenium,selenium-webdriver,internet-explorer,selenium-iedriver,Python,Selenium,Selenium Webdriver,Internet Explorer,Selenium Iedriver,鉴于此代码: 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

鉴于此代码:

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是错误的

这一过程被“卡住”了

好像页面没有正确加载

我正在使用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浏览会话


根据:

保护模式 在Windows Vista或Windows 7上的Internet Explorer 7或更高版本上,必须将每个区域的保护模式设置设置为相同的值。该值可以打开或关闭,只要每个分区的值相同。要设置受保护模式设置,您必须从“工具”菜单中选择“Internet选项”,然后单击“安全”选项卡。对于每个区域,选项卡底部都会有一个复选框,标记为启用保护模式

此外,
@JimEvans
在他的文章中明确提到:

不过,使用该功能并不能解决根本问题。如果跨越受保护模式边界,可能会导致非常意外的行为,包括挂起、元素位置不工作以及未传播的单击。为了提醒人们注意这一潜在问题,该功能被冠以听起来很吓人的名字,如Java中的“忽略安全域”和.NET中的“忽略受保护的节点设置”等。我们真的认为,告诉用户使用此设置会在他们的代码中引入潜在的不好因素会阻止其使用,但事实并非如此


解决方案 访问url
https://www.google.ro/?safe=active&ssui=on
使用驱动启动的浏览上下文,您可以使用以下最小代码块:

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升级到当前级别
  • 将硒升级到当前水平
  • 将IEDriverServer升级至最新级别
注意:根据最佳实践,Selenium客户端和InternetExplorerDriver是同步发布的,您必须尝试使用同一主要版本的两个二进制文件

  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 执行
    @测试
  • 始终在
    tearDown(){}
    方法中调用
    driver.quit()
    ,以优雅地关闭和销毁Web驱动程序和Web客户端实例

工具书类 您可以在以下内容中找到一些相关的详细讨论:

from selenium import webdriver

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