2017-09-13 117 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