Can't open a link as a background tab - Java, Selenium, IE

ぃ、小莉子 提交于 2019-12-25 03:13:37

问题


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

I've also tried

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

It actually opens it in a new window.

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?


回答1:


There is no reason to do this.

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

driver.switchTo().defaultContent();

to get back to the tab you were on.

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


来源:https://stackoverflow.com/questions/27628386/cant-open-a-link-as-a-background-tab-java-selenium-ie

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