我正在使用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
答案 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
希望它会对你有所帮助.. :)