action.sendKeys(body, Keys.CONTROL + “j”) dosen't open the download page

五迷三道 提交于 2019-12-22 01:03:48

问题


I am using Java and Selenium to write tests for Chrome. I need to open the download page at one point so I used:

action.sendKeys(Keys.CONTROL + "j").build().perform();

but it does NOT open the page. then I added this line before it as I though it might work but it didn't:

WebElement body = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//body[@id='body']")));
action.sendKeys(body, Keys.CONTROL + "j").build().perform();

The weird point is that

action.sendKeys(Keys.CONTROL + "a").build().perform();

Works!!

NOTE: I do not want to use Robot class as it will open the page on other browsers if the focus is not on the test target browser.


回答1:


Try using like Below code, it is working perfectly at my end ...

Actions builder = new Actions(driver);
builder.keyDown(Keys.CONTROL).sendKeys("j").keyUp(Keys.CONTROL).build().perform();

I'd suggest not to go for chrome://downloads as this will not work in IE and FF but CTRL + j will work on all chrome, IE and FF.




回答2:


Do you need to use the key binding? You could just navigate to the URL chrome://downloads/ ...

Edit: Ofc, this is not the ideal solution for cross-browser compability. But definitely a good workaround for chrome.



来源:https://stackoverflow.com/questions/37492102/action-sendkeysbody-keys-control-j-dosent-open-the-download-page

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