我是使用Java,Selenium和Webdriver的新手
我使用:selenium 3 beta3,Java jdk1.8.0_101和firefox 48.01 我也使用Geckodriver,因为使用sel3需要它。
我正在尝试打开一个网址。打开浏览器正在运行。 我使用的代码如下。
package AutomatedScripts;
import org.openqa.selenium.WebDriver; // driver for Webdriver
import org.openqa.selenium.firefox.FirefoxDriver; //driver for Firefox
public class GoogleSearchOneTime {
public static void main(String[] agrs) {
System.setProperty("webdriver.firefox.marionette","C:\\selenium-3.0.0\\geckodriver\\geckodriver.exe");
// Launch a firefox browser
WebDriver driver = new FirefoxDriver();
// go to Google.com
driver.get("http://www.google.com");
// go to google.com
// driver.navigate().to("http://www.google.com");
//Enter search terms
//driver.findElement(By.id("lst-ib")).clear();
//driver.findElement(By.id("lst-ib")).sendKeys("Google");
//Click on the searh button
//driver.findElement(By.name("btnG")).click();
//check page title contacts the search term
}
}
答案 0 :(得分:2)
将System.setProperty替换为如下
System.setProperty("webdriver.gecko.driver", "C:\\selenium-3.0.0\\geckodriver\\geckodriver.exe");
此处有一个示例链接,您可以参考Launching firefox browser using Geckodriver