Chromedriver not clicking on object coordinates while in W10 VM
Chromedriver not clicking on object coordinates while in W10 VM
I have a veeeeery weird issue I can not get solved, I am using Selenium together with Java, all bindings are up to date and Chrome browsers is up to date.
My main testing is done in Windows machines using mobile emulation.
When I launch my test cases in a Windows 7 real machine / Windows 7 Virtual Machine or Windows 10 real machine they are working ok, but when I launch them in any Windows 10 Virtual Machine selenium starts clicking on wrong coordinates.
IE. I have a button placed in (70, 612), selenium is able to get the element coordinates without issues but when using click() it is actually clicking somewhere else (it is opening a banner or an event).
If I use javascript click it is working with no issues, it is just selenium click() command and only in W10 VM (I have tried a Windows Server 2016 VM as well).
I have tried to low and raise mobile pixel density and always having same results.
As an extra, this issue is not reproducible when testing on chrome desktop (no emulation) so I think it should be related with how Selenium is calculating where to click.
I hope someone had the same issue and be able to show some light to this.
Best regards.
Some Code trials as requested:
I am parsing device metrics (Height,Width,PixelRatio)
Map<String, Object> deviceMetrics = new HashMap<String, Object>();
deviceMetrics.put("width", this.width);
deviceMetrics.put("height", this.height);
deviceMetrics.put("pixelRatio", this.pixelRatio);
Map<String, Object> mobileEmulation = new HashMap<String, Object>();
mobileEmulation.put("deviceMetrics", deviceMetrics);
mobileEmulation.put("userAgent", this.userAgent);
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
chromeOptions.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
chromeOptions.setCapability(CapabilityType.ROTATABLE, true);
chromeOptions.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,
org.openqa.selenium.UnexpectedAlertBehaviour.ACCEPT);
if(scope.equals("performance"))if(scope.equals("performance"))
chromeOptions.setProxy(seleniumProxy);
chromeOptions.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
Then init remoteWD.
try {
return new RemoteWebDriver(new URL("http://xxxxxx.xxxx.com:4444/wd/hub"), chromeOptions);
} catch (MalformedURLException e) {
e.printStackTrace();
System.out.println("Driver creation failed");
return new ChromeDriver(chromeOptions);
}
Device Metrics Example:
switch (driverName) {
case "Samsung S7":
setDeviceData(GALAXY_S7_USER_AGENT, orientation, 360, 640, 2.8, driverName);
deviceKind="mobile";
break;
case "Samsung S6":
setDeviceData(GALAXY_S6_USER_AGENT, orientation, 360, 640, 2.8, driverName);
deviceKind="mobile";
break;
case "Samsung S5":
setDeviceData(GALAXY_S5_USER_AGENT, orientation, 360, 640, 2.8, driverName);
deviceKind="mobile";
break;
And this is an example of a simple test case
@Test(retryAnalyzer = RetryAnalyzerImpl.class)
public void LogInLogOut() throws IOException, ParserConfigurationException, SAXException {
ATUReports.setAuthorInfo("Daniel Prado Pino", Utils.getCurrentTime(),"1.0");
driver.get("https://www.elotrolado.net");
sleep(3000);
log.info("Click");
driver.findElement(By.cssSelector("#h-mobile-nav-btn")).click();
log.info("Clicked");
sleep(10000);
}
note: For this test case I hace Selenium StandAlone 3.1.3 running together with Chromedriver 2.40 in a Windows Server 2016 Virtual Machine. I have reproduced it as well in Windows 10 Virtual Machine executed through jenkins / maven.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Some code trials please
– Prany
Jun 29 at 15:24