import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Test {
public static void main(String[] args) {
//WebDriver driver=new FirefoxDriver();
//Chrome
//System.setProperty("webdriver.chrome.driver","F:\\chromedriver\\chromedriver.exe");
//WebDriver driver=new ChromeDriver();
//IE
System.setProperty("webdriver.ie.driver","F:\\drivers\\IEDriverServer.exe");
WebDriver driver=new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("http://facebook.com");
driver.findElement(By.id("email")).sendKeys("ssss@gmail.com");
driver.findElement(By.id("pass")).sendKeys("123r45");
driver.findElement(By.id("u_0_x")).click();
}
}
上面的代码用于在firefox,chrome中自动化facebook,即仅在ff中脚本工作正常但不在chrome中,即
答案 0 :(得分:0)
您的代码没有任何问题。您可以尝试这一点,将安装程序.exe放在项目的源文件夹中。对我来说工作正常,我用镀铬试过它。
//For Chrome
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir")+"\\src\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//For IE
System.setProperty("webdriver.ie.driver", System.getProperty("user.dir")+"\\src\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();