无法打开链接作为背景标签 - 爪哇,硒,IE [英] Can't open a link as a background tab - Java, Selenium, IE

查看:158
本文介绍了无法打开链接作为背景标签 - 爪哇,硒,IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以当然在Internet Explorer(9)我不能得到一个链接在后台标签页中打开。我试过几件事情:

So of course in internet explorer (9) I cannot get a link to open in a background tab. I've tried a few things :

Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
driver.findElement(By.name(THE_LINK)).click();
r.keyRelease(KeyEvent.VK_CONTROL);

我也试过

String link = Keys.chord(Keys.CONTROL, Keys.RETURN);
driver.findElement(By.name(THE_LINK)).sendKeys(link);

它实际上打开它在一个新窗口。

It actually opens it in a new window.

当我手动工作和Ctrl +单击它工作正常,并在后台选项卡中打开。我已经尝试重置浏览器设置,并做了很多不同的东西,但当然,预期这是行不通的。

When I'm working manually and ctrl+click it works as expected and opens in a background tab. I've tried resetting browser settings and doing a lot of different things but of course, it doesn't work as expected.

任何人都见过这个?任何人有不同的事情对我来说来试试呢?

Anyone seen this before? Anyone got a different thing for me to try?

推荐答案

有没有理由这样做。

如果你点击链接,只需切换回原来的背景下使用:

If you click the link, just switch back to the original context by using:

driver.switchTo().defaultContent();

要回你的标签。

如果不工作,你可能需要做

If that doesn't work, you might have to do

driver.switchTo().window(driver.getWindowHandles()[0]);  // i'm not at my programming computer so i can't remember the actual syntax ;)

这篇关于无法打开链接作为背景标签 - 爪哇,硒,IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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