【问题标题】:Firefox 48 is not opening the any URL in the script after using selenium web driver 3.0Firefox 48 在使用 selenium web driver 3.0 后没有打开脚本中的任何 URL
【发布时间】:2016-12-11 11:38:10
【问题描述】:

我已经将 selenium webdriver 版本更新到 3.0 beta 之后,我在 eclipse ide 中生成了一个脚本。在我运行脚本之后,Firefox 被打开但没有重定向到 url。

这是selenium ide生成的简单代码

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class Selenium {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @BeforeClass(alwaysRun = true)
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://www.google.co.in/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testF() throws Exception {
    driver.get(baseUrl + "/?gws_rd=ssl");
    driver.findElement(By.id("lst-ib")).clear();
    driver.findElement(By.id("lst-ib")).sendKeys("hi");
    driver.findElement(By.id("lst-ib")).clear();
    driver.findElement(By.id("lst-ib")).sendKeys("hifi");
  }

  @AfterClass(alwaysRun = true)
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

【问题讨论】:

标签: firefox selenium-webdriver selenium-ide eclipse-neon


【解决方案1】:

这是因为功能问题,就像其他浏览器供应商提供给 Selenium 的其他驱动程序一样,Mozilla 发布了一个可执行调用 geckodriver,它将与浏览器一起运行。

您需要下载最新的可执行文件geckodriver 并将此下载路径从您的机器设置为系统属性,以使用 Firefox 驱动程序运行您的测试用例,如下所示:

 System.setProperty("webdriver.gecko.driver","path/to downloaded/geckodriver.exe");
 DesiredCapabilities capabilities = DesiredCapabilities.firefox();
 capabilities.setCapability("marionette", true);
 WebDriver driver = new FirefoxDriver(capabilities);

 //Now do your further stuff with Firefox driver

【讨论】:

    【解决方案2】:

    要运行导出的 IDE 测试,请确保 leg-rc 包位于 类路径。

    Selenium 3 更改日志中提到了这一点。请参考change log

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-25
      • 2017-12-27
      • 1970-01-01
      • 1970-01-01
      • 2017-03-25
      • 2014-11-11
      • 2017-11-12
      • 1970-01-01
      相关资源
      最近更新 更多