0

I'm writing integration/e2e tests and for some reason any selenium driver commands don't see to be working with chromedriver, but they are working flawlessly with firefox driver and the firefox headless driver.

Commands tried: moveByOffset, and doubleClick

Tried both Geb's Interact method

interact {
 doubleClick(centerClickable)
}

and accessing the webdriver directly:

def driver = browser.getDriver()
Actions action = new Actions(driver)
WebElement element= driver.findElement(By.className("vis-drag-center"))
def doubleclick = action.doubleClick(element).build()
doubleclick.perform()

Both methods work with the firefox driver. Neither work with chrome driver.

GebConfig.groovy file is set up as thus:

import io.github.bonigarcia.wdm.WebDriverManager
import org.openqa.selenium.Dimension
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeOptions
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.firefox.FirefoxOptions

def chromeWebDriverVersion = '70.0.3538.67'

def driverFirefox = {
  WebDriverManager.firefoxdriver().setup()
  def driver = new FirefoxDriver()
  driver.manage().window().setSize(new Dimension(width, height))
  return driver
}

// ChromeDriver reference: https://sites.google.com/a/chromium.org/chromedriver/
// Download and configure ChromeDriver using https://github.com/bonigarcia/webdrivermanager
def driverChrome = {
  WebDriverManager.chromedriver().version(chromeWebDriverVersion).setup()
  def driver = new ChromeDriver()
  driver.manage().window().setSize(new Dimension(width, height))
  return driver
}

environments {
  firefox {
    driver = driverFirefox
  }
  chrome {
    driver = driverChrome
  }
//driver = driverFirefox
driver = driverChrome

I also tried version 2.43 of chrome.

Additional information:

  • Mac Mojave
  • Selenium v 3.7.0
  • geb v 2.2
  • spockcore v 1.1-groovy-2.4
  • groovy v 2.4.5
  • webdrivermanager v 3.0.0

If anyone is interested, what the test is doing: Selecting a vis.js element by clicking on it. Sleeping for a second (code not included here), then opening/activating it by double clicking it. Or dragging it.

Apart from the selenium actions everything works fine with chromedriver and geb. It's only now that I need the doubleClick and moveByOffset (not move to an element!) that I'm getting issues getting things to work properly

I found a similar question on here, might be the same issue. Maybe not. But there's no solution provided: Selenium Web Driver DragAndDropToOffset in Chrome not working?

Any help is hugely appreciated.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
lmartinl
  • 1
  • 4
  • I think you would have a better chance to get good answers if you could also point us to a publicly available web site against which to run your test or if you would provide the HTML page source code here by editing your question. Please always try to help your potential helpers by providing an [MCVE](http://stackoverflow.com/help/mcve) instead of just snippets which nobody can just compile and run. – kriegaex Dec 23 '18 at 02:36

2 Answers2

0

I just had a little bit of time and was curious because I never tried to perform a double-click in any of my tests before. So I used this page as a test case and ran the following test with both Firefox and Chrome drivers:

package de.scrum_master.stackoverflow

import geb.spock.GebReportingSpec
import org.openqa.selenium.By
import org.openqa.selenium.interactions.Actions

class DoubleClickTest extends GebReportingSpec {
  def "double-click via Geb interaction"() {
    given:
    go "https://demo.guru99.com/test/simple_context_menu.html"
    def doubleClickButton = $("button", text: "Double-Click Me To See Alert")

    expect:
    withAlert {
      interact {
        doubleClick(doubleClickButton)
      }
    } == "You double clicked me.. Thank You.."
  }

  def "double-click via Selenium action"() {
    given:
    go "https://demo.guru99.com/test/simple_context_menu.html"
    def doubleClickButton = driver.findElement(By.tagName("button"))
    def doubleClick = new Actions(driver).doubleClick(doubleClickButton).build()

    expect:
    withAlert {
      doubleClick.perform()
    } == "You double clicked me.. Thank You.."
  }
}

It works flawlessly, both ways of double-clicking trigger the expected Javascript alert.

I am not even using the latest driver version 2.45 but 2.41 against Chrome 71 64-bit on Windows 10. Besides, I also use bonigarcia's Webdriver Manager. I have no idea what is wrong with your setup. My Selenium version is 3.14.0, a bit newer than yours, Geb 2.2, Spock 1.1-groovy-2.4, Groovy 2.4.7.

Maybe it is a MacOS thing? I cannot verify that. Maybe you just run my test first, then maybe upgrade your Selenium and if that also does not help try to downgrade the Chrome driver in order to find out if the problem could be driver version related.


Update: I upgraded to Chrome driver 2.45, the test still works.


Update 2022-02-16: Updated the test to work with another example page, because the old URL still exists, but the Javascript there no longer works.

kriegaex
  • 63,017
  • 15
  • 111
  • 202
0

Thank you for your response kriegaex. Your tests work for me as well. This leads me to think there's just some lower-level interaction between differences in how selenium's chromedriver and firefox driver have implemented the doubleclick and dragAndDropBy actions + the way our application responds to commands.

For any other people observing similar behaviour, I use a work-around where I add an additional action for chromedriver. Perhaps it's nicer to actually find out which KEYDOWN events etc. you should be using and fire those, or perhaps find out why application isn't responding to these events. But I feel like enough time is spent on this already :)

  if (browser.getDriver().toString().contains("chrome")) {
//      Work-around for chromedriver's double-click implementation
    content.click()
  }

  interact {
    doubleClick(content)
  }

And for the dragAndDropBy:

  def drag(Navigator content, int xOff, int yOff) {
    //Work-around: move additional time for when chrome driver is used.
    int timesToMove = browser.getDriver().toString().contains("chrome") ? 2 : 1

    interact {
      clickAndHold(content)
      timesToMove.times {
        moveByOffset(xOff, yOff)
      }
      release()
    }
  }
lmartinl
  • 1
  • 4