Selenium-IE驱动程序:单击js中定义的链接,并使用_blankdo nothing

Selenium-IE驱动程序:单击js中定义的链接,并使用_blankdo nothing,selenium,selenium-iedriver,Selenium,Selenium Iedriver,我测试一个站点,它们是在新选项卡中打开的链接。它在IE、FireFox和Chrome上手动运行,在FireFox和Chrome上使用Selenium,但在IE上不使用Selenium,它什么都不做,没有错误。 我检查了代码 HTML: 爪哇: (definition of the driver) System.setProperty("webdriver.ie.driver","pathToMyDriverIE"); In

我测试一个站点,它们是在新选项卡中打开的链接。它在IE、FireFox和Chrome上手动运行,在FireFox和Chrome上使用Selenium,但在IE上不使用Selenium,它什么都不做,没有错误。
我检查了代码
HTML:

爪哇:

(definition of the driver)  
    System.setProperty("webdriver.ie.driver","pathToMyDriverIE");                           
    InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions();
    internetExplorerOptions.setCapability("RequireWindowFocus", true);
    internetExplorerOptions.setCapability("EnablePersistentHover", true);
    internetExplorerOptions.setCapability("EnableNativeEvents", true);
    internetExplorerOptions.setCapability("ignoreZoomSetting", true);
    internetExplorerOptions.setCapability("ie.ensureCleanSession", true);
    internetExplorerOptions.setCapability("enableElementCacheCleanup", true);
    internetExplorerOptions.destructivelyEnsureCleanSession();
    internetExplorerOptions.setCapability("ignoreProtectedModeSettings", true);
    internetExplorerOptions.setCapability("UnexpectedAlertBehavior", UnexpectedAlertBehaviour.ACCEPT);
    internetExplorerOptions.setCapability("IntroduceInstabilityByIgnoringProtectedModeSettings", true);         
    internetExplorerOptions.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
    driver = new InternetExplorerDriver(internetExplorerOptions); 


(function to click on the link)
public void clickOnLink(boolean withJs){
    WebElement W = driver.findElement(By.id("idA"));
    if(withJs){
         ((JavascriptExecutor)driver).executeScript("arguments[0].click();", W);
    }
    else{
        W.click();
    }
}
我想在打开一个新窗口时手动操作(因为我需要与after交互,在新选项卡中使用IE很难),但我无法获得JS中定义的链接。没有空白就没有问题。
有人有主意了吗?
硒:3.11.0;InternetExplorerDriver:3.9(32位);JDK8

提前感谢。

好的,经过一些搜索和测试,IE驱动程序在打开新选项卡或窗口时似乎遇到了大问题。我使用这样一个新的WebDriver:

public static void clicOnLink(){
    //driver = WebDriver in use
    WebElement w = driver.findElement(By.id("idA"));
    w.click();
    if(DriverIsIE && driver.getWindowHandles().size()==1){
        if(w.getTagName().equals("a") && (w.getAttribute("href")!=null && !w.getAttribute("href").isEmpty())){
            openWithNewDriver();
        }
        else{
            String source = driver.getPageSource();
            int s0 = source.indexOf("$(\"#idA\").on(\"click\"");
            String s2 = source.substring(s0,source.indexOf("});"),s0);
            String[] ss = s2.substring(s2.indexOf("window.open")).split(",");
            String urlToOpen = ss[0].replaceAll("\"","").replace("window.open(","").replace(")","");
            openWithNewDriver(urlToOpen);
        }
    }
}

public static void openWithNewDriver(String url){
    WebDriver driver2 = setUpDriver();//definition of the driver
    if(url!=null && !url.isEmpty()){
        driver2.get(url);
    }
    //ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));
    //to do something on the new window
    driver2.close();
}

如果它对将来的某个人有帮助。

好的,经过一些搜索和测试,IE驱动程序在打开新的选项卡或窗口时似乎有很大的问题。我使用这样一个新的WebDriver:

public static void clicOnLink(){
    //driver = WebDriver in use
    WebElement w = driver.findElement(By.id("idA"));
    w.click();
    if(DriverIsIE && driver.getWindowHandles().size()==1){
        if(w.getTagName().equals("a") && (w.getAttribute("href")!=null && !w.getAttribute("href").isEmpty())){
            openWithNewDriver();
        }
        else{
            String source = driver.getPageSource();
            int s0 = source.indexOf("$(\"#idA\").on(\"click\"");
            String s2 = source.substring(s0,source.indexOf("});"),s0);
            String[] ss = s2.substring(s2.indexOf("window.open")).split(",");
            String urlToOpen = ss[0].replaceAll("\"","").replace("window.open(","").replace(")","");
            openWithNewDriver(urlToOpen);
        }
    }
}

public static void openWithNewDriver(String url){
    WebDriver driver2 = setUpDriver();//definition of the driver
    if(url!=null && !url.isEmpty()){
        driver2.get(url);
    }
    //ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));
    //to do something on the new window
    driver2.close();
}

如果这对将来的人有帮助。

显然我的问题不是新的[link]()显然我的问题不是新的[link]()
public static void clicOnLink(){
    //driver = WebDriver in use
    WebElement w = driver.findElement(By.id("idA"));
    w.click();
    if(DriverIsIE && driver.getWindowHandles().size()==1){
        if(w.getTagName().equals("a") && (w.getAttribute("href")!=null && !w.getAttribute("href").isEmpty())){
            openWithNewDriver();
        }
        else{
            String source = driver.getPageSource();
            int s0 = source.indexOf("$(\"#idA\").on(\"click\"");
            String s2 = source.substring(s0,source.indexOf("});"),s0);
            String[] ss = s2.substring(s2.indexOf("window.open")).split(",");
            String urlToOpen = ss[0].replaceAll("\"","").replace("window.open(","").replace(")","");
            openWithNewDriver(urlToOpen);
        }
    }
}

public static void openWithNewDriver(String url){
    WebDriver driver2 = setUpDriver();//definition of the driver
    if(url!=null && !url.isEmpty()){
        driver2.get(url);
    }
    //ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));
    //to do something on the new window
    driver2.close();
}