我想我的機器上運行下面的代碼(WIN XP & IE8)如何設置爲可執行IE驅動程序路徑中硒的webdriver
public class bookie {
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
driver = new InternetExplorerDriver(caps);
baseUrl = "http://book.theautomatedtester.co.uk/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testbookie() throws Exception {
System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");
driver.get(baseUrl + "/");
driver.findElement(By.linkText("Chapter1")).click();
driver.findElement(By.id("radiobutton")).click();
new Select(driver.findElement(By.id("selecttype"))).selectByVisibleText("Selenium Core");
driver.findElement(By.linkText("Home Page")).click();
driver.findElement(By.linkText("Chapter2")).click();
driver.findElement(By.id("but1")).click();
driver.findElement(By.xpath("//input[@value='Sibling Button']")).click();
driver.findElement(By.linkText("Index")).click();
driver.findElement(By.linkText("Chapter1")).click();
new Select(driver.findElement(By.id("selecttype"))).selectByVisibleText("Selenium Grid");
driver.findElement(By.linkText("Home Page")).click();
driver.quit();
}
但它爲我提供的堆棧跟蹤
java.lang.IllegalStateException:驅動程序可執行文件 的路徑必須由webdriver.ie.driver系統屬性設置;在 org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) 在 org.openqa.selenium.ie.InternetExplorerDriverService.access $ 1(InternetExplorerDriverService.java:1) 在 org.openqa .selenium.ie.InternetExplorerDriverService $ Builder.build(InternetExplorerDriverService.java:230) 在 org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263) 在 org.openqa.selenium.ie.InternetExplorerDriver (InternetExplorerDriver.java:182) 在 org.openqa.selenium.ie.InternetExplorerDriver。(InternetExplorerDriver.java:159) 在bookie.setUp(bookie.java:19)在 sun.reflect.NativeMethodAccessorImpl.invoke0(本機方法)維持在 sun.reflect.DelegatingMethodAccessorImpl.invoke(來源不明) sun.reflect.NativeMethodAccessorImpl.invoke(來源不明)在 java.lang.reflect.Method.invoke(來源不明)在 org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(在 org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12 FrameworkMethod.java:47) ) 在 org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 在 org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 在 組織.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner的.java:70) 在 org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)在 org.junit.runners .ParentRunner $ 1.schedule(ParentRunner.java:63)at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)at org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)at org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)at org.junit.runners.ParentRunner。運行(ParentRunner.java:309) org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run (TestExecution.java:38) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:673) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) 在 org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main (RemoteTestRunner。的java:196)
由於您尚未爲IEDriver指定* exact *路徑,因此它將查找PATH變量並可能是當前工作目錄。我還建議刪除您設置的不穩定設置。 – Arran
謝謝你的迴應阿蘭.. 一切工作正常..但仍然我想學習/理解事情更密切。 所以..我理解你說的大部分內容,除了「不穩定設置」部分。 請你詳細說明..馬新手.. – LeonarD
可能重複[驅動程序可執行文件必須由webdriver.ie.driver系統屬性設置](http://stackoverflow.com/questions/10995314/driver-executable-必須-e -ed驅動程序 - 即驅動程序系統屬性) – Sebastian