Cannot find web elements at “chrome://downloads/” page

陌路散爱 提交于 2019-12-08 13:06:15

问题


I am using Java and Selenium to write tests for Chrome. Sometimes I need to get to chrome://downloads/ and click on CLEAR ALL button. I can get to the page by

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

but I cannot click on the button, whatever xpath I use it says no such element


回答1:


Below here JavascriptExecutor example to perform click on CLEAR ALL button using selenium :-

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

Tested in Chrome Version 50.0.2661.102 m

Hope it will help you..:)



来源:https://stackoverflow.com/questions/37503202/cannot-find-web-elements-at-chrome-downloads-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!