2017-09-13 116 views
0

我能夠在selenium java 3.4.0和geckodriver 0.16上執行我的腳本,但自新更新以來,某些功能已棄用,因此我不得不更改瀏覽器配置代碼,現在它沒有完全執行。它不執行整個腳本。無法在selenium中運行腳本java

代碼之前(之前升級到Java 3.5.3):

System.setProperty("webdriver.firefox.marionette", "C:\\geckodriver.exe"); 
     FirefoxProfile profile = new FirefoxProfile(); 
     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", 
       "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;"); 
     profile.setPreference("browser.helperApps.alwaysAsk.force", false); 
     profile.setPreference("browser.download.manager.showWhenStarting", false); 
     profile.setPreference("browser.download.folderList", 2); 
     profile.setPreference("browser.download.dir", prodDownloadPath); 
     DesiredCapabilities dc = DesiredCapabilities.firefox(); 
     dc.setCapability(FirefoxDriver.PROFILE, profile); 
     dc.setCapability("marionette", true); 
     driver = new FirefoxDriver(dc); 
     driver.manage().window().maximize(); 
     driver.manage().timeouts().implicitlyWait(160, TimeUnit.SECONDS); 
     driver.get(productionUrl); 
     driver.findElement(By.linkText("Demand Summary")).click(); 
     Thread.sleep(2000); 
     driver.findElement(
       By.xpath("//table[@class='TextObject']//tr//td[contains(text(),'16 Weeks Historical Trend')]")).click(); 
     Thread.sleep(2000); 
     WebElement imageUrl = driver.findElement(By.xpath(".//*[@class='QvFrame Document_CH80']/div[2]/div[2]/img")); 
     Actions oAction = new Actions(driver); 
     oAction.moveToElement(imageUrl); 
     oAction.contextClick(imageUrl).build().perform(); 
     driver.findElement(By.linkText("Send to Excel")).click(); 
     Thread.sleep(1000); 

以前的版本:

System.setProperty("webdriver.firefox.marionette", "C:\\geckodriver.exe"); 
     FirefoxProfile profile = new FirefoxProfile(); 

     profile.setPreference("browser.helperApps.neverAsk.saveToDisk", 
       "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;"); 
     profile.setPreference("browser.helperApps.alwaysAsk.force", false); 
     profile.setPreference("browser.download.manager.showWhenStarting", false); 
     profile.setPreference("browser.download.folderList", 2); 
     profile.setPreference("browser.download.dir", prodDownloadPath); 
     driver = new FirefoxDriver(profile); 
     driver.manage().window().maximize(); 

     driver.manage().timeouts().implicitlyWait(160, TimeUnit.SECONDS); 

     driver.get(productionUrl); 
     driver.findElement(By.linkText("Demand Summary")).click(); 
     Thread.sleep(2000); 
     driver.findElement(
       By.xpath("//table[@class='TextObject']//tr//td[contains(text(),'16 Weeks Historical Trend')]")).click(); 
     Thread.sleep(2000); 
     WebElement imageUrl = driver.findElement(By.xpath(".//*[@class='QvFrame Document_CH69']/div[2]/div[2]/img")); 
     Actions oAction = new Actions(driver); 
     oAction.moveToElement(imageUrl); 
     oAction.contextClick(imageUrl).build().perform(); 
     driver.findElement(By.linkText("Send to Excel")).click(); 
     Thread.sleep(2000); 

最新的代碼(升級到3.5.3後)

-Selenium Java 3.4.0 
-Selenium Server Standalone 3.4 
-Gecko 0.16 
-FF 46.0  

最新版本:

-Selenium Java 3.5.3 
-Selenium Server Standalone 3.5.3 
-Gecko 0.18 
-FF 55.0.3  

我腳本的執行過程中不被org.openqa.selenium.ElementNotInteractableException:例外。我應該使用哪些版本的組合?還是我需要更改我的代碼或什麼?請幫忙 。

+0

你嘗試https://stackoverflow.com/questions/43868009/how-to-resolve -elementnotinteractableexception合硒的webdriver ?? – nullpointer

+0

我已經添加了那行代碼。我編輯了我的代碼。請看看 –

+0

我認爲版本組合存在一些問題,但我無法弄清楚。任何人都可以建議目前的工作組合 –

回答

0

使用Implicit wait

driver.get("https://stackoverflow.com/"); 
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 

explicit wait

WebDriverWait wait = new WebDriverWait(driver, waitTime); 
wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); 

僅供參考

WebDriverWait Wait= new WebDriverWait(driver,20); 
Wait.until(ExpectedConditions.elementToBeClickable (By.id("Locator"))); 
+0

。您的答案似乎評論 – NarendraR

+0

我想點擊該元素以及我應該怎麼做 –

+0

應該有一個方法名稱爲elementToBeClickable。試試這個 – iamsankalp89