找不到网页元素" chrome:// downloads /"页

时间:2016-05-28 19:47:45

标签: java selenium selenium-webdriver selenium-chromedriver

我正在使用Java和Selenium为Chrome编写测试。有时我需要前往chrome://downloads/并点击CLEAR ALL按钮。我可以通过

进入该页面
RemoteWebDriver driver = (RemoteWebDriver) driverChrome;
        driver.executeScript("window.open();");
        Thread.sleep(500);
        tabs = new ArrayList<String>(driverChrome.getWindowHandles());
        driverChrome.switchTo().window(tabs.get(1));
        Thread.sleep(500);
        driverChrome.get("chrome://downloads/");

但是我无法点击按钮,无论我使用的xpath是什么no such element

1 个答案:

答案 0 :(得分:2)

在此JavascriptExecutor示例下,使用selenium点击CLEAR ALL按钮: -

JavascriptExecutor executor = (JavascriptExecutor)driver
executor.executeScript("var dm = document.getElementsByTagName('downloads-manager')[0];var toolbar = dm.shadowRoot.getElementById('toolbar');var actions = toolbar.shadowRoot.getElementById('actions');actions.getElementsByClassName('clear-all')[0].click();");

Chrome Version 50.0.2661.102 m

中测试过

希望它会对你有所帮助.. :)