【问题标题】:Unable to run scripts in selenium java无法在 selenium java 中运行脚本
【发布时间】:2017-09-13 18:24:57
【问题描述】:

我能够在 selenium java 3.4.0 和 geckodriver 0.16 上执行我的脚本,但是自从新的更新以来,一些功能已被弃用,因为我不得不更改我的浏览器配置代码,现在它没有完全执行。它不会执行整个脚本。

代码之前(升级到 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); 

最新代码(升级到 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);

以前的版本:

-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:exception。我应该使用什么版本组合?还是我需要更改我的代码或其他什么?请帮忙。

【问题讨论】:

  • 我已经在我的代码中添加了该行。我已经编辑了我的代码。请看一下
  • 我认为版本组合存在一些问题,但我无法弄清楚。任何人都可以建议当前的工作组合
  • 您遇到的异常是什么,您可以将有关异常的完整日志粘贴到控制台中
  • 尝试用壁虎换木偶

标签: java selenium selenium-webdriver testng


【解决方案1】:

使用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")));

【讨论】:

  • 我想点击那个元素,然后我应该怎么做
  • 应该有一个方法名为 elementToBeClickable。试试这个
  • 没有这种方法
  • 喜欢这个 WebDriverWait Wait= new WebDriverWait(driver,20); Wait.until(ExpectedConditions.elementToBeClickable (By.id("Locator")));
  • 你有方法吗
猜你喜欢
  • 1970-01-01
  • 2013-08-31
  • 1970-01-01
  • 1970-01-01
  • 2013-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多