2017-09-07 41 views
0

我正在測試像Paint一樣的GWT + SMARTGWT應用程序,並試圖使用Selenium Webdriver查找此Web應用程序的元素。我用來定位元素的方法是通過這些元素的相對XPath,但我目前面臨的問題是,此方法在瀏覽器(如Chrome,Firefox和Edge)上正常工作,但不在IE瀏覽器上正常工作。我個人電腦上的IE版本是11.1593.14393.0。在IE瀏覽器中,這個相對的XPath方法提供了一個TimeOutException。我已經給了明確的等待:無法找到在IE瀏覽器中使用Selenium的SmartGWT應用程序的元素

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瀏覽器的工作。

回答

0

因此,我能夠通過使用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); 
相關問題