Selenium - FireFox/Marionette driver is too fast to control

1.4k views Asked by At

After updating to the Firefox to version 52, i had to update gecko driver to v17. But all my previous scripts fail in Firefox, becase it is too fast and not wating for element on the page to load.

I am now forced to add Thread.sleep wait for each click. Is there any solution you guys can help me with?

Works in Chrome better, but need both to be working the same.

I run testNg and the exception i get is: Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'

I fixed it by insterting Thread.sleep which is not recommended but this is the only thing that works. Fluent wait didnot work or me

1505314327534 geckodriver INFO Listening on 127.0.0.1:42753 1505314328131 mozprofile::profile INFO Using profile path C:\User\AppData\Local\Temp\rust_mozprofile.NX5A3KOOQr 1505314328136 geckodriver::marionette INFO Starting browser C:/Program Files/Mozilla Firefox/firefox.exe with args [] 1505314328150 geckodriver::marionette INFO Connecting to Marionette on localhost:65331 1505314331570 Marionette INFO Listening on port 65331

2

There are 2 answers

0
undetected Selenium On

One of the objective of Test Automation is to reduce the Test Execution time. So it should make us glad if the driver of Firefox i.e. geckodriver which uses Marionette acts faster. Now your question must be how to synchronize the geckodriver with the real-time Mozilla Firefox Browser.

  1. In your question you mentioned about adding Thread.sleep(n). Slowing down inducing Thread.sleep(n) is not a part of Best Programming practices. It degrades the performance. So lets look at the other available options.
  2. Next you mentioned about not waiting for element on the page to load. This is a common issue faced while we use WebDriver. The simplest way to address this is to induce ImplicitWait. In short, by introducing ImplicitWait the driver will poll the HTML DOM for the configured amount of time looking out for the element or elements. By that time the element or elements for which you had been looking for may be available in the HTML DOM. An example of ImplicitWait is as follows:

    • Python:

      driver.implicitly_wait(10)
      
    • Java:

      driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
      

You can find the official documentation here and also find a detailed stackoverflow discussion here.

  1. ImplicitWait can slow down your Test Execution quite drastically. So in that case ExplicitWait comes to our rescue. In short, ExplicitWait is a code block you define, configure and implement for the WebDriver instance to wait for a certain condition to be met before proceeding for the next line of code. An example of ExplicitWait is as follows:

    • Python:

      password = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "your_xpath")))
      password.send_keys("your_password")
      
    • Java:

      WebDriverWait wait = new WebDriverWait(driver, 20);
      WebElement password = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("your_xpath")));
      password.sendKeys("your_password");
      

You can find the official documentation here and also find a detailed stackoverflow discussion here.

0
Gamcusa On

Works in Chrome better, but need both to be working the same.

I run testNg and the exception i get is: Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'

I fixed it by insterting Thread.sleep which is not recommended but this is the only thing that works. Fluent wait didnot work or me