Selenium 3.0.1与IE11在Windows 10上找不到元素(在Windows 7上使用IE11正常工作)

der*_*kmw 7 python selenium selenium-webdriver internet-explorer-11 selenium-iedriver

  • 操作系统:Windows 10
  • 浏览器:IE11
  • Selenium(Python)包:3.0.1
  • IEWebDriverServer.exe:3.1.0

我们正准备将我们的自动化节点迁移到Windows 10,在我们的测试中,我们发现尽管我们的脚本在FF,IE和Chrome上的Win7上运行良好,但它们在Windows 10上仅在IE上失败(适用于FF和Chrome) ).

当运行agianst IE时,浏览器实例化并且webdriver能够看到浏览器(我尝试了一个简单的命令,如driver.back(),返回上一页).但是,我们无法获得任何find_element ...调用工作.无论是id,name,css,xpath等,脚本都会失败,说明找不到给定id/name/css/xpath的元素(无论我试图用什么方法来查找webelement).

我已经看到有关安全更新的帖子打破了这一点,并建议还原更新.这是一年前的事情,似乎随后的更新已经解决了这个问题.

我还阅读了有关确保所有区域的保护模式相同,注册表值等的帖子.这些建议都没有奏效.

以下是我正在使用的示例脚本(当修改为在Chrome或Firefox中运行时)仅在IE11中不起作用:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Ie()
driver.implicitly_wait(30)
driver.maximize_window()

# navigate to the application home page
driver.get("http://www.google.com")

# get the search textbox
search_field = driver.find_element_by_id("lst-ib")
Run Code Online (Sandbox Code Playgroud)

运行此脚本的错误是:

selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with id == lst-ib
Run Code Online (Sandbox Code Playgroud)

Sim*_*n N 0

虽然我确信您现在不会那么烦恼,但几天前我记录了同样的问题,但我仍然陷入困境(单击此处)。我进一步将问题范围缩小到安全性。如果您增加日志记录,您将看到以下行:

W 2017-03-06 17:27:41:539 Script.cpp(494) -2147024891 [Access is denied.]: Unable to execute code, call to IHTMLWindow2::execScript failed
W 2017-03-06 17:27:41:540 Script.cpp(180) Cannot create anonymous function
W 2017-03-06 17:27:41:540 ElementFinder.cpp(98) A JavaScript error was encountered executing the findElement atom. 
Run Code Online (Sandbox Code Playgroud)

我已尝试打开/关闭所有安全选项,但无济于事。我在本地遇到了这个问题,并且还没有设置我的 CI 环境,所以希望当我启动它时它应该能够正常工作(祈祷)。

PS我不认为你的虚拟机坏了!!