我为我的基本Maven和Selenium项目openGmail使用了2个类。我使用Selenium 3.5和Firefox 47.0.1和Gecodriver 0.18。即使在代码中定义了Geckodriver错误
我的主类是:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class MainClass {
WebDriver driver = new FirefoxDriver();
public void setup() {
String Path_GecoDriver="C:/Personal/Selenium/setup/geckodriver-v0.18.0-win64";
System.setProperty("webdriver.firefox.marionette", Path_GecoDriver+"/geckodriver.exe");
System.setProperty("webdriver.gecko.driver", Path_GecoDriver+"/geckodriver.exe");
}
public void OpenBrowser() {
String url="http://google.co.in";
driver.get(url);
}
public void LoginGmail() throws InterruptedException {
String username ="username";
String passwd = "passwd";
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.id("identifierId")).sendKeys(username);
WebElement cli=driver.findElement(By.xpath("//*[text()='Next']"));
cli.click();
Thread.sleep(1000);
driver.findElement(By.xpath("//input[@name='password']")).sendKeys(passwd);
driver.findElement(By.xpath("//*[text()='Next']")).click();
}
public void CloseBrowser() {
driver.close();
}
}
我的其他类: -
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class TestngClass {
MainClass mc=new MainClass();
@Before
public void sp() {
mc.setup();
mc.OpenBrowser();
}
@Test
public void LG() throws InterruptedException {
mc.LoginGmail();
}
@After
public void CB() {
mc.CloseBrowser();
}
}
我收到错误
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information
我试图通过执行它的测试把我的System.setProperty(道具,路径/到/驱动程序)放在我的@Before和@test也没有改变,我仍然得到错误。
如果我使用一个类,那么一切工作正常,所以我想我把我的system.setProperty放在错误的地方。
我最近开始使用Java和Selenium。我甚至试图把我的Maven项目的src/main /资源我壁虎驱动程序EXE为In System.setProperty("webdriver.gecko.driver", "<Path to your WebDriver>"), what is meant by "Path to your WebDriver"?
它应该是 “webdriver.gecko.driver”,而不是 “webdriver.firefox.marionette”。改变这一点,你应该没问题。 –
更新了我的回答 –
让我知道你是否能够摆脱'IllegalStateException' – DebanjanB