gpt4 book ai didi

java - 如何在 Selenium WebDriver 中设置可执行 IE 驱动程序的路径

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:17:42 25 4
gpt4 key购买 nike

我正在尝试在我的机器上运行以下代码(win XP & IE8)

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: The path to the driver executable must be set by the webdriver.ie.driver system property; at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:105) at org.openqa.selenium.ie.InternetExplorerDriverService.access$1(InternetExplorerDriverService.java:1) at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.build(InternetExplorerDriverService.java:230) at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:263) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:182) at org.openqa.selenium.ie.InternetExplorerDriver.(InternetExplorerDriver.java:159) at bookie.setUp(bookie.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) at org.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) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at 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.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

最佳答案

将驱动程序放置在某个位置,例如C:\Selenium\iexploredriver.exe

然后

File file = new File("C:/Selenium/iexploredriver.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();

下一行应该是 setUp() 函数的第一行

System.setProperty("webdriver.ie.driver", "IEDriverServer.exe");   

关于java - 如何在 Selenium WebDriver 中设置可执行 IE 驱动程序的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21325663/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com