Unable to run scripts in selenium java

0 votes
asked Sep 13, 2017 by siddhesh-kalgaonkar

I was able to execute my scripts on selenium java 3.4.0 and geckodriver 0.16 but since the new update ,some of the functions are deprecated due to which I had to change my browser configuration code and now it is not executing entirely. It doesn't execute whole script .

Before Code (before upgrading to 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);
        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); 

Latest Code (After upgrading to 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);

Previous Versions:

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

Latest Versions:

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

I am getting org.openqa.selenium.ElementNotInteractableException:exception during the execution of scripts. What combination of versions should I use ? or do I need to change my code or something ? Please help .

1 Answer

0 votes
answered Sep 13, 2017 by iamsankalp89

Use Implicit wait

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

or explicit wait

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

For reference

WebDriverWait Wait= new WebDriverWait(driver,20);
Wait.until(ExpectedConditions.elementToBeClickable (By.id("Locator")));
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...