我试图设置Selenium Webdriver与Java的Browserstack一起使用,以进行自动测试。我安装了Selenium for Java,然后从浏览器堆栈的站点https://www.browserstack.com/automate/java#configure- capabilities复制并粘贴了代码,以建立示例自动化测试。
我javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java从终端运行(JavaSample.java是带有selenium配置代码和示例测试的文件),并且出现以下错误:
javac -classpath selenium-server-standalone-2.48.2.jar JavaSample.java
JavaSample.java:1: error: package org.openqa.selenium does not exist import org.openqa.selenium.By; ^ JavaSample.java:2: error: package org.openqa.selenium does not exist import org.openqa.selenium.Platform; ^ JavaSample.java:3: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebDriver; ^ JavaSample.java:4: error: package org.openqa.selenium does not exist import org.openqa.selenium.WebElement; ^ JavaSample.java:5: error: package org.openqa.selenium.remote does not exist import org.openqa.selenium.remote.DesiredCapabilities; ^ JavaSample.java:6: error: package org.openqa.selenium.remote does not exist import org.openqa.selenium.remote.RemoteWebDriver; ^ JavaSample.java:18: error: cannot find symbol DesiredCapabilities caps = new DesiredCapabilities(); ^ symbol: class DesiredCapabilities location: class JavaSample JavaSample.java:18: error: cannot find symbol DesiredCapabilities caps = new DesiredCapabilities(); ^ symbol: class DesiredCapabilities location: class JavaSample JavaSample.java:25: error: cannot find symbol WebDriver driver = new RemoteWebDriver(new URL(URL), caps); ^ symbol: class WebDriver location: class JavaSample JavaSample.java:25: error: cannot find symbol WebDriver driver = new RemoteWebDriver(new URL(URL), caps); ^ symbol: class RemoteWebDriver location: class JavaSample JavaSample.java:27: error: cannot find symbol WebElement element = driver.findElement(By.name("q")); ^ symbol: class WebElement location: class JavaSample JavaSample.java:27: error: cannot find symbol WebElement element = driver.findElement(By.name("q")); ^ symbol: variable By location: class JavaSample
我不确定如何解决这个问题,因为我只是按照Browserstack上的说明进行操作,而且我对Java的了解很少。
您必须从Selenium Downloads下载 Java 的“ Selenium客户端和WebDriver语言绑定” 。您可以通过单击此处的链接直接下载。
包括下载的ZIP文件中存在的所有JAR文件。要在Java类路径中包含多个JAR的selenium-server-standalone JAR,如果您是在本地运行测试是必需的。执行该命令java -jar selenium-server-standalone-2.48.2.jar将启动Selenium服务器,该服务器需要在本地启动Selenium测试。如果要在BrowserStack上运行测试,则无需使用它。
selenium-server-standalone JAR
java -jar selenium-server-standalone-2.48.2.jar
还将建议使用IDE for Java。最受欢迎的是IntelliJIdea,Eclipse和Netbeans。