我正在使用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
最佳答案
下面的JavascriptExecutor
示例使用硒执行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
中测试希望它能对您有所帮助.. :)