java无法在IE浏览器中使用Selenium定位SmartGWT应用程序的元素
我正在测试一个GWT+SMARTGWT应用程序,比如Paint,并尝试使用SeleniumWebDriver定位此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中为所有级别启用/禁用受保护模式,但这个方法不起作用。除此之外,我还尝试选中选项旁边的框-“允许活动内容在我的计算机上运行文件”,但此方法也失败了
我应该如何解决我的问题
这是我的密码。首先,我将单击应用程序顶部栏上的Insert按钮,单击Insert按钮后,将启动一个窗口,我将在其中单击Close按钮
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 executor查找元素,如下所示:
WebElement Insert = driver.findElement(By.xpath(InsertPath));
Thread.sleep(2000);
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("arguments[0].click();", Insert);
遗憾的是,这种方法在IE浏览器中也不起作用
# 1 楼答案
因此,我能够通过使用Internet Explorer的最新驱动程序定位元素,并在我的代码中为IE浏览器提供以下所需的功能