How to open new tab in IE using selenium (java) and open a url in that tab (not window)(如何使用 selenium(java)在 IE 中打开新选项卡并在该选项卡(不是窗口)中打开一个 url)
问题描述
如何使用 selenium (java) 在 IE 中打开一个新选项卡并在该选项卡(不是窗口)中打开一个 url?我正在使用以下代码打开一个新标签页?
How do I open a new tab in IE using selenium (java) and open a url in that tab (not window)? I am using the below code to open a new tab?
driver.get("https://google.com/");
//below line of code opens a new tab but does sets control on new tab.
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");//opens new tab
// As control does not sets on new tab, the below link opens on first tab only..
driver.get("https://facebook.com/");//but load facebook in first tab i.e on google page
谁能告诉我,如何将控制权转移到新标签页,以便 facebook 链接在该新标签页中打开.
Can anyone tell me, how to shift control to new tab so that the facebook link opens in that new tab.
你好
我使用 Selenium Web-Driver 版本 2.40 和 IE 11.0
I using Selenium Web-Driver Version 2.40 and IE 11.0
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.manage().window().maximize();
driver.get("https://google.com/");
driver.findElement(By.cssSelector("Body")).sendKeys(Keys.CONTROL + "t");//opens new tab
//Store the current window handle
String winHandleBefore = driver.getWindowHandle();
//Perform the click operation that opens new window //Switch to new window open
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);
driver.get("https://facebook.com/");
}
// Perform the actions on new window
//Close the new window, if that window no more required
driver.close();
//Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
//continue with original browser (first window)
我无法在同一窗口的新标签页上打开 facebook..
I am not able to open facebook on new tab of same window..
问候沙申克·戈亚尔
推荐答案
你需要使用
driver.switchTo().window(String)
像打开新窗口一样切换到出现的窗口.
to switch to the window that has come up just as you would with opening a new window.
这篇关于如何使用 selenium(java)在 IE 中打开新选项卡并在该选项卡(不是窗口)中打开一个 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 selenium(java)在 IE 中打开新选项卡并在该
基础教程推荐
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01