如何使用Selenium在IE中打开多个选项卡而不是多个窗口

时间:2017-08-09 16:04:51

标签: java selenium internet-explorer

我正在使用selenium Java。我需要在新打开的选项卡中打开多个选项卡并打开不同的URL。我尝试使用getWindowHandles(),它不适用于Internet Explorer。请为此建议正确的解决方案。

以下是我使用的代码:

import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Multiple 
{
    public static void main(String[] args) throws Exception 
    {
        System.setProperty("webdriver.ie.driver","C:\\Selenium\\IEDriverServer.exe");       
        WebDriver d = new InternetExplorerDriver();     
        d.get("https://www.google.co.in/");
        d.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);        
        d.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
        //d.switchTo().window(d.getWindowHandles().iterator().next());                                  
        ArrayList<String> tabs2 = new ArrayList<String> (d.getWindowHandles());
        d.switchTo().window(tabs2.get(1));          
        d.get("https://www.facebook.com/login");                        
    }
}

使用上面的代码我可以打开新标签但第二个网址没有输入。 任何人都可以为我提供完美的解决方案吗?

0 个答案:

没有答案
相关问题