簡體   English   中英

單擊方法不適用於Chrome模擬器

[英]Click method is not working with chrome emulator

以下是我的設置的詳細信息:

chrome = 67.0.3396.87,chromedriver = 2.40.565498,硒版本2.53.0

下面是模擬器代碼-

public ChromeOptions getChromeEmulators(int width, int height) {
    Map<String, Object> deviceMetrics = new HashMap<String, Object>();
    Map<String, Object> mobileEmulation = new HashMap<String, Object>();
    ChromeOptions chromeOptions = new ChromeOptions();
    try {
        deviceMetrics.put("width", width);           
        deviceMetrics.put("height", height);
        deviceMetrics.put("pixelRatio", 3.0);
        mobileEmulation.put("deviceMetrics", deviceMetrics);
        mobileEmulation.put("userAgent",
"Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) 
AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile 
Safari/535.19");
       chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    }catch (Exception e) {
        e.printStackStarce();
    }
    return chromeOptions;
}

click選項不適用於chrome仿真器,但適用於以上版本的chrome瀏覽器。 有人可以幫忙嗎?

從過去的幾個版本開始,這是chromedriver存在的已知問題。 尚未解決。 此時,唯一的解決方法是使用chromerdriver:2.33.506120 + chrome:61.0.3163.79

請參考以下錯誤:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=2144&desc=2

https://bugs.chromium.org/p/chromedriver/issues/detail?id=2172

另外,您可以嘗試使用JavascriptExecutor(盡管這不是首選)

JavascriptExecutor script click. JavascriptExecutor js = (JavascriptExecutor) 
driver; js.executeScript("arguments[0].click();",element);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM