无法在IE浏览器中使用Selenium定位SmartGWT应用程序的元素 [英] Unable to locate the elements of SmartGWT application using Selenium in IE browser

查看:219
本文介绍了无法在IE浏览器中使用Selenium定位SmartGWT应用程序的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm testing a GWT + SMARTGWT application like Paint and I'm trying to locate the elements of this web application using Selenium Webdriver. The method which I have used to locate the elements is by the relative XPath of those elements but the problem which I am currently facing is that this method is working correctly on the browsers like Chrome, Firefox, and Edge but not on the IE browser. The version of IE on my PC is 11.1593.14393.0. In the IE browser, this relative XPath method is giving a TimeOutException. I have given the explicit wait:

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

IE浏览器无法找到元素。其他元素有时也会出现以下异常:

The IE browser is not able to find the element. I am also getting the following exception sometimes for other elements:

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浏览器的保护模式,但是这种方法无效。我也尝试选中选项旁边的框 - 允许活动内容在我的电脑上运行文件,但此方法也失败。

Among the troubleshooting solutions to this issue, I tried enabling/disabling the protected mode in IE for all the levels but this method didn't work. Along with that, I also tried checking the box next to the option - "Allow active content to run files on My Computer" but this method also failed to work.

我该如何解决我的问题?

What should I do to fix my issue?

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

This is my code. Here firstly, I will click on the Insert button located on the top bar of the application and after clicking on the Insert button, a window will launch on which I will click on the Close button.

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执行程序在我的代码中查找元素如下:

I also used finding the element using Javascript executor in my code as follows:

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

不幸的是,这种方法也无法在IE浏览器中运行。

Sadly, this method also failed to work in the IE browser.

推荐答案

/ p>

So, I was able to locate the elements by using the latest driver of the Internet Explorer and giving the following desired capabilities in my code to the IE browser.

    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);

这篇关于无法在IE浏览器中使用Selenium定位SmartGWT应用程序的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆