无法在 IE 浏览器中使用 Selenium 定位 SmartGWT 应用程序的元素

Unable to locate the elements of SmartGWT application using Selenium in IE browser

我正在测试像 Paint 这样的 GWT + SMARTGWT 应用程序,我正在尝试使用 Selenium Webdriver 定位此 Web 应用程序的元素。我用来定位元素的方法是通过这些元素的相对 XPath,但我目前面临的问题是这种方法在 Chrome、Firefox 和 Edge 等浏览器上正常工作,但在IE浏览器。我电脑上的IE版本是11.1593.14393.0。在 IE 浏览器中,这个相对的 XPath 方法给出了 TimeOutException。我已经明确等待:

wait.until(ExpectedConditions.elementToBeClickable(webelement));

IE浏览器找不到该元素。对于其他元素,我有时也会收到以下异常:

Exception in thread "main" org.openqa.selenium.InvalidSelectorException: Unable to locate an element with the xpath expression //img[contains(@src,'Insert XXX'] because of the following error:
Error: Bad token: ]

在解决这个问题的解决方案中,我尝试了enabling/disabling IE 中所有级别的保护模式,但这种方法不起作用。除此之外,我还尝试选中选项旁边的框 - “允许活动内容到我的计算机上的 运行 文件”,但此方法也无法正常工作。

我应该怎么做才能解决我的问题?

这是我的代码。首先,我将单击应用程序顶部栏上的“插入”按钮,单击“插入”按钮后,将启动一个 window,我将在其上单击“关闭”按钮。

public static void main(String[] args) throws InterruptedException {

        System.setProperty("webdriver.ie.driver", "D:\SELENIUM\Drivers\iedriverserver.exe");
        WebDriver driver = new InternetExplorerDriver();
        Thread.sleep(3000);
        driver.get(baseURL);
        WebDriverWait wait = new WebDriverWait(driver, 10);
        final String InsertPath = "//img[contains(@src,'Insert XXXX')]";
        final String closePath="//img[contains(@src,'close')]";
        WebElement Insert = driver.findElement(By.xpath(InsertPath));
        wait.until(ExpectedConditions.elementToBeClickable(Insert));
        Thread.sleep(2000);
        Insert.click(); 
        WebElement close = driver.findElement(By.xpath(closePath));
        wait.until(ExpectedConditions.elementToBeClickable(close));
        Thread.sleep(3000);
        close.click();
        }
     }

编辑: 我还在代码中使用 Javascript 执行器查找元素,如下所示:

        WebElement Insert = driver.findElement(By.xpath(InsertPath));
        Thread.sleep(2000);
        JavascriptExecutor jse = (JavascriptExecutor) driver;
        jse.executeScript("arguments[0].click();", Insert);

遗憾的是,此方法在IE浏览器中同样无效

因此,我能够通过使用 Internet Explorer 的最新驱动程序并在我的代码中为 IE 浏览器提供以下所需功能来定位这些元素。

    DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
    ieCapabilities.setCapability("requireWindowFocus", true);   
    ieCapabilities.setCapability("unexpectedAlertBehaviour", "accept");
    ieCapabilities.setCapability("ignoreProtectedModeSettings", true);
    ieCapabilities.setCapability("disable-popup-blocking", true);
    ieCapabilities.setCapability("enablePersistentHover", true);*/
    System.setProperty("webdriver.ie.driver", "D:\IEDriverServer.exe");
    WebDriver driver = new InternetExplorerDriver(ieCapabilities);