Selenium 3.0.1 with IE11 not finding elements on Windows 10 (Works fine on Windows 7 with IE11)
Asked Answered
D

2

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
Dragnet answered 1/3, 2017 at 21:38 Comment(8)
Could you add the code that you cant get to execute (It does sound like you have hot a security feature in I.E. 10 in which case there not much you can do )Teets
It's something as simple as: self.driver.find_element_by_xpath("//td[text()='Login']").click() this will work fine on Windows 10 for FF and Chrome but not in IE11. I have tried various alternatives like find_element_by_css_selector, by_id, by_name, etc. But in all cases, it states that it cannot find the element. I feel like there has to be something obvious I am not aware of by the fact that no one else seems to have posted this issue.Dragnet
Just to add, I created a very simple test using the sample examples listed for creating a basic selenium script (in this case, a python example). I see the same behavior. IE loads and navigates to the URL, but it cannot find any elements. The script fails saying "unable to find element with id ...". Any help here or suggestions would be appreciated.Dragnet
the solution given here https://mcmap.net/q/758785/-unable-to-find-element-on-closed-window-on-ie-11-with-selenium worked for me for the same environment that you are in.Pudency
Thanks, I never tried the first method (setting initial URL) but have already the registry set. I just tried adding the capability 'initialBrowserUrl' but still no go.Dragnet
Quick update for anyone else struggling with this. I already tried uninstalling any security updates (to rule them out) but nothing has helped. I finally decided to just create a new VM with fresh Windows 10 and it's working. So I cannot say for certain what happened to this original VM but some where along the line, something changed and Selenium stopped working for IE. it's frustrating but I feel, after wasting 4 full days trying to get this to work, that it is better to just start fresh and ditch this broken VM.Dragnet
For completeness, have you checked every point listed here: github.com/SeleniumHQ/selenium/wiki/…Dinka
Yes, that is what I initially followed and since following those did not help, started venturing out and trying other suggestions.Dragnet
M
0

Although I'm sure you not that bothered now, I logged the same issue a few days ago and I'm still stuck (click here). I have further narrowed down the problem to security. If you increase logging you will see the below lines:

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. 

I have tried every security option on/off but to no avail. I'm getting the problem locally and haven't set up my CI environment so hoping that when i spin it up it should just work (fingers crossed).

P.S. I don't think you had a broken VM!!

Mixer answered 8/3, 2017 at 3:53 Comment(1)
Right, sorry for the term 'broken VM'. I know the VM is not necessarily broken but I suspect some update (whether a patch/security update to OS or Browser) has happened which is causing this. However, being that I don't seem to have a way to undo this, I said that. If you find a way to get it to work, I'm all ears and will be grateful. I kept this VM in place and am going to do a compare between the two to see if I can isolate it as well.Dragnet
G
0

Whenever I stumble across a 'NoSuchElementException' (albeit not on Windows or IE), this has always worked:

Add these imports:

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

Then to locate the element:

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

Credit to Web Scraping with Python. I hope this helps, although at the moment I don't have windows or IE to verify this in advance.

Gulledge answered 8/3, 2017 at 4:33 Comment(1)
Thanks for the suggestion but no, this does not work for IE. It's important to note that the simple find element calls work fine in FF and CH. Just not IE11 on Windows 10.Dragnet

© 2022 - 2024 — McMap. All rights reserved.