Chromedriver在W10 VM中未点击对象坐标

时间:2018-06-29 14:54:06

标签: selenium click windows-10 virtual-machine

我遇到了一个无法解决的怪异问题,我将Selenium与Java一起使用,所有绑定都是最新的,而Chrome浏览器是最新的。

我的主要测试是在Windows计算机上使用移动仿真完成的。

当我在Windows 7真实计算机/ Windows 7虚拟机或Windows 10真实计算机中启动测试用例时,它们可以正常工作,但是当我在任何Windows 10虚拟机中启动它们时,硒将开始单击错误的坐标。

IE。我在(70,612)中放置了一个按钮,selenium可以毫无问题地获取元素坐标,但是当使用click()时,它实际上是在其他地方单击(它正在打开横幅或事件)。

如果我使用javascript单击,则可以正常使用,这只是硒click()命令,仅在W10 VM中(我也尝试过Windows Server 2016 VM)。

我试图降低并提高移动像素密度,并始终获得相同的结果。

另外,在chrome桌面上进行测试(无仿真)时,此问题无法重现,因此我认为它应与Selenium如何计算点击位置有关。

我希望有人遇到同样的问题,并且能够对此有所启发。

最诚挚的问候。

一些要求的代码试用:

我正在解析设备指标(高度,宽度,像素比)

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);

然后初始化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);

    }

设备指标示例:

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;

这是一个简单测试用例的例子

@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);
}

注意:对于此测试用例,我将Selenium StandAlone 3.1.3与Chromedriver 2.40一起在Windows Server 2016虚拟机中运行。我也在通过jenkins / maven执行的Windows 10虚拟机中复制了它。

0 个答案:

没有答案