【问题标题】:Unable to locate the elements of SmartGWT application using Selenium in IE browser无法在 IE 浏览器中使用 Selenium 定位 SmartGWT 应用程序的元素
【发布时间】:2017-09-07 10:42:12
【问题描述】:

我正在测试一个 GWT + SMARTGWT 应用程序,比如 Paint,我正在尝试使用 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: ]

在此问题的故障排除解决方案中,我尝试在 IE 中为所有级别启用/禁用保护模式,但此方法不起作用。除此之外,我还尝试选中选项旁边的框 - “允许活动内容在我的电脑上运行文件”,但此方法也失败了。

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

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

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浏览器中也失效了。

【问题讨论】:

    标签: java internet-explorer xpath selenium-webdriver gwt


    【解决方案1】:

    因此,我能够通过使用最新的 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);
    

    【讨论】:

      猜你喜欢
      • 2018-02-14
      • 2015-06-08
      • 1970-01-01
      • 2021-11-19
      • 2015-12-08
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多