-1

I am writing some tests using selenium with Python. So far my suite works perfectly with Chrome and Firefox. However, the same code is not working when I try with the Edge (EdgeHTML). I am using the latest version at the time of writing which is release 17134, version: 6.17134. My tests are running on Windows 10.

The problem is that Edge is not waiting for the page to load. As part of every test, a login is first performed. The credentials are entred and the form submitted. Firefox and Chrome will now wait for the page we are redirected to, to load. However, with Edge, the next code is executed as soon as the login submit button is clicked which of course results in a failed test.

Is this a bug with Edge? It seems a bit too fundamental to be the case. Does the browser need to be configured in a certain manner? I cannot see anything in the documentation.

This is the code run with the last statement resulting in a redirect as we have logged in:

self.driver.find_element_by_id("login-email").send_keys(username)
self.driver.find_element_by_id("login-password").send_keys(password)
self.driver.find_element_by_id("login-messenger").click()

Edge decides it does not need to wait and will then execute the next code which is to navigate to a protected page. The code is:

send_page = SendPage(driver)
send_page.load_page()

More concisely:

self.driver.find_element_by_id("login-messenger").click()
# should wait now for the login redirect before excuting the line below but it does not!
self.driver.get(BasePage.base_url + self.uri)

I can probably perform a workaround by waiting for an element on the extent page to be present thus making Edge wait. This does not feel like the right thing to do. I certainly don't want to have to keep making invasive changes just for Edge.

Any advice please on what I should do?

TylerH
  • 20,799
  • 66
  • 75
  • 101
James M
  • 21
  • 4
  • Update the question with your code trials. – undetected Selenium Dec 10 '19 at 12:45
  • You could import the time package and using the [time.sleep(secs) method](https://www.pythoncentral.io/pythons-time-sleep-pause-wait-sleep-stop-your-code/) or using the [WebDriverWait()](https://selenium-python.readthedocs.io/waits.html#) to wait the page load. – Zhi Lv Dec 10 '19 at 15:39
  • I could do a WebDriverWait() and look for something on the page I know should load. It won't affect the other browsers but I'm reluctant to do something that I feel I should not. The purpose of this question is to see if this is a know issue with a established workaround or else to find out if I was doing something wrong. – James M Dec 10 '19 at 16:58

1 Answers1

0

Is this a bug with Edge? It seems a bit too fundamental to be the case. Does the browser need to be configured in a certain manner? I cannot see anything in the documentation.

No, I think it is not a bug with Edge browser. Because of the difference between the browser's performance, perhaps Edge browser will spend more time to load the page.

Generally, we could use the time.sleep(secs) method, WebDriverWait() method and implicitly_wait() method to wait the page load.

The code block below shows you how to wait for a page load to complete. It uses a timeout. It waits for an element to show on the page (you need an element id). Then if the page is loaded, it shows page loaded. If the timeout period (in seconds) has passed, it will show the timeout error.

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

driver = webdriver.Firefox()
driver.get('https://pythonbasics.org')
timeout = 3
try:
    element_present = EC.presence_of_element_located((By.ID, 'main'))
    WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
    print("Timed out waiting for page to load")
finally:
    print("Page loaded")

More detail information, please check the following articles.

Wait until page is loaded with Selenium WebDriver for Python

How to wait for elements in Python Selenium WebDriver

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30