action.sendKeys(body,Keys.CONTROL +"j")无法打开下载页面 [英] action.sendKeys(body, Keys.CONTROL + "j") dosen't open the download page

查看:54
本文介绍了action.sendKeys(body,Keys.CONTROL +"j")无法打开下载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java和Selenium编写针对Chrome的测试.我需要一次打开下载页面,所以我使用了:

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

奇怪的是,

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

有效!

注意:我不想使用Robot类,因为如果焦点不在测试目标浏览器上,它将在其他浏览器上打开页面.

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.

推荐答案

尝试使用类似下面的代码,它在我的末端运行良好...

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

我建议不要进行chrome://下载,因为这在IE和FF中不起作用,但是CTRL + j在所有chrome,IE和FF上都可以工作.

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.

这篇关于action.sendKeys(body,Keys.CONTROL +"j")无法打开下载页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆