7
  • OS: Windows 10
  • Browser: IE11
  • Selenium (Python) package: 3.0.1
  • IEWebDriverServer.exe: 3.1.0

We are getting ready to migrate our automation nodes to Windows 10 and during our tests, we found that although our scripts work fine on Win7 on FF, IE, and Chrome, they fail on Windows 10 only for IE (works fine for FF and Chrome).

When running agianst IE, the browser instantiates and webdriver is able to see the browser (I tried a simple command such as driver.back() which returns to previous page). However, we cannot get any find_element... calls to work. Whether it be by id, name, css, xpath, etc. The script will just fail stating that no element was found for the given id/name/css/xpath (whatever method I tried to use to find the webelement).

I have seen posts regarding security updates that broke this and suggesting to revert the update. This was a year ago though and it seems subsequent updates have fixed this issue.

I have also read posts about making sure the protected mode is the same across all zones, a registry value, etc. None of these suggestions have worked though.

Here is the sample script I am using which (when modified to run in Chrome or Firefox passes) does not work in IE11 only:

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")

The error from running this script is:

selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with id == lst-ib
4

2 回答 2

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. 

我已经尝试了每个安全选项的开/关,但无济于事。我在本地遇到问题并且没有设置我的 CI 环境,所以希望当我启动它时它应该可以正常工作(手指交叉)。

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

于 2017-03-08T03:53:43.857 回答
0

每当我偶然发现“NoSuchElementException”(尽管不是在 Windows 或 IE 上)时,这总是有效的:

添加这些导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

然后定位元素:

search_field = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, """//*[@id="lst-ib"]""")))
search_field.send_keys('Example')

归功于 Python 的 Web Scraping。我希望这会有所帮助,尽管目前我没有 Windows 或 IE 来提前验证这一点。

于 2017-03-08T04:33:40.353 回答