【发布时间】:2017-11-08 18:59:26
【问题描述】:
我在 selenium Grid 的帮助下运行基本的 selenium 代码。
以下是步骤:
第 1 步:- 下载最新版本的 selenium Standalone server (3.4.0);
第二步 :- 使用命令java - jar <path of selenium standalone server>\\selenium-server-standalone-3.4.0.jar -role hub 创建HUB -> 成功运行;
第三步 :- 使用命令java -jar selenium-server-standalone-3.4.0.jar -role hub -node http://localhost:4444/grid/register 创建节点 -> 运行成功;
第 4 步:- 使用以下代码创建了一个简单的 selenium 程序:
public class ClassName {
public static void main(String args[]) throws InterruptedException, MalformedURLException {
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
DesiredCapabilities cap=DesiredCapabilities.firefox();
cap.setPlatform(Platform.WINDOWS);
cap.setBrowserName("firefox");
URL url = new URL("http://localhost:4444/wd/hub");
WebDriver wd1 = new RemoteWebDriver(url, cap);
wd1.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
wd1.manage().window().maximize();
wd1.get("http://www.clickindia.com/");
wd1.findElement(By.linkText("Post Free Ad")).click();
Thread.sleep(3000);
wd1.findElement(By.linkText("Select category manually")).click();
Thread.sleep(3000);
WebElement country = wd1.findElement(By.id("combo_0"));
Select sel = new Select(country);
sel.selectByVisibleText("Jobs");
}
}
在运行上面的代码时,抛出了以下异常:
注意:如果我在没有 remoteDriver 的情况下运行上面的代码,并且作为一个常见的 WebDriver 程序,那么它可以正常工作和运行。
selenium 独立服务器和 Gecko 文件的位置相同。
Gecko 版本为 v0.16.0
提前致谢
【问题讨论】:
标签: java selenium selenium-webdriver selenium-grid geckodriver