1
driver = webdriver.Ie("C:\\IEDriverServer.exe")
driver.get(testurl)
driver.refresh()
time.sleep(5)
data = driver.find_element_by_id("__content0-value-scr")

So I'm trying to find an element by it's id using Selenium (Python) and Internet Explorer, because I'm limited to Internet Explorer due to company regulations.

My problem is as follows: on driver.get(testurl), selenium loads the page but IE first starts up with the IEDriver landing page. Only after that, it loads the requested url.

The problem here is that Selenium recognizes the IE Driver landing page as the url to be loaded and therefore ignores the page I want to search on, which gets loaded after that.

Has anyone got an idea on how to work around this?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Druckermann
  • 681
  • 2
  • 11
  • 31
  • What exactly do you mean by *Selenium recognizes the IE Driver landing page as the url to be loaded*? Also why do you use `driver.refresh()` right after `driver.get(testurl)`? – Andersson Nov 22 '18 at 21:44
  • In ´data = driver.find_element_by_id....´ , selenium does not find the requested id, because it searches the IE Driver Server landing page for this id. I used ´driver.refresh()´ to try and get selenium to load the page I need instead of the IE Driver Server landing page. – Druckermann Nov 22 '18 at 21:48
  • Why do you think so? There are several reasons not to find element on page – Andersson Nov 22 '18 at 21:48
  • Because it worked on a test machine with the firefox webdriver which means that there is not an issue with the connection or incorrect page loading. – Druckermann Nov 22 '18 at 21:50
  • Besides that, Internet Explorer opens up whenever I call `driver.get` then shows the landing page for a second, after that opens the requested url. – Druckermann Nov 22 '18 at 21:52
  • 1
    Could you use the `WebDriverWait` method to wait for something on the landing page before you do the `driver.get()`? – John Anderson Nov 22 '18 at 21:54
  • Share exception and HTML code sample for target element (copied from IE) – Andersson Nov 22 '18 at 21:58
  • Waiting doesn't work. This yields me: NoSuchWindowException: Unable to find element on closed window. And then: `NoSuchElementException: Message: Unable to find element with id == __content0-value-scr` – Druckermann Nov 22 '18 at 22:01
  • Your diagnosis ("Selenium recognizes the IE Driver landing page as the url to be loaded and therefore ignores the page I want to search on") is likely incorrect (if that was true no tests on IE would ever work), but you don't provide enough details for anyone to be helpful. – timbre timbre Nov 22 '18 at 22:50

1 Answers1

2

When you use Selenium, IEDriverServer and Internet Explorer, while IEDriverServer initiates a new IE Browser session, IE Browser first starts up with the IEDriver landing page and then loads the requested url.

Incase Selenium recognizes the IEDriverServer's landing page as the url to be loaded, in that case the solution would be to induce WebDriverWait for the Page Title to be equivalent to the actual page title of the AUT (Application Under Test).

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    testurl = "https://www.facebook.com/" # replace with the url of the AUT
    driver = webdriver.Ie(executable_path=r'C:\path\to\IEDriverServer.exe')
    driver.get(testurl)
    WebDriverWait(driver, 10).until(EC.title_contains("Facebook")) # # replace with the title of the AUT
    data = driver.find_element_by_id("__content0-value-scr")
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352