如何使用selenium(java)在IE中打开新选项卡并在该选项卡中打开一个URL(不是窗口)
如何使用selenium(java)在IE中打开一个新选项卡并在该选项卡(不是窗口)中打开一个URL? 我使用以下代码打开新标签?
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 ie on google page
任何人都可以告诉我,如何将控制转移到新选项卡,以便在新选项卡中打开Facebook链接。
你好
我使用Selenium Web-Driver版本2.40和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 ..
关心Shashank Goyal
你需要使用
driver.switchTo().window(String)
切换到出现的窗口,就像打开一个新窗口一样。
ArrayList tabHandles1 = new ArrayList (driver.getWindowHandles()); driver.switchTo().window(tabHandles1.get(index));
你可以使用arrayList tabhandles1传递索引值的位置或者可以迭代到所有选项卡
- Java:如何使用JNI函数停止调用一系列C ++函数的Thread?
- IndexReader.getFieldNames Lucene 4
- 实现AbstractMultiTenantConnectionProvider
- 如何在PrimeFaces dataTable列中使用换行符(漂亮打印)显示XML内容?
- JUnit:NoClassDefFoundError:org / junit / runner / manipulation / Filter
- 为文本框创建气球工具提示?
- 在Java 8u60中在WebView中加载本地JavaScript文件
- Sprint引导数据JPA:没有类型为’java.util.Set ‘的限定bean
- 如何使用Jersey API从宁静的Web服务发送和接收JSON数据