How to make selenium wait before getting contents from the actual website which loads after the landing page through IEDriverServer and IE
Asked Answered
C

1

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?

Constituency answered 22/11, 2018 at 21:31 Comment(9)
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)?Lomasi
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.Constituency
Why do you think so? There are several reasons not to find element on pageLomasi
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.Constituency
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.Constituency
Could you use the WebDriverWait method to wait for something on the landing page before you do the driver.get()?Wicklow
Share exception and HTML code sample for target element (copied from IE)Lomasi
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-scrConstituency
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.Obryant
E
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")
    
Emrick answered 23/11, 2018 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.