我在这里和网络上搜索了我的问题的答案,但找不到任何对我有帮助的东西。希望这不是一个愚蠢的问题。

我正在尝试让Selenium 2使用各种浏览器工作。我使用Mac作为集线器和节点,并使用Windows pc作为节点。我的问题是Chrome。我想在Mac上启动Java代码,并在Windows pc上运行Selenium测试。要使Chrome在本地主机上运行,​​我需要以下代码:

System.setProperty("webdriver.chrome.driver", "Users/xxxxx/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

这会在中心/节点Mac上打开Chrome。如何在Windows PC上打开它?我可以将任何东西传递给ChromeDriver()类吗?

我尝试使用RemoteWebDriver,并且具有以下内容:
System.setProperty("webdriver.chrome.driver", "/Users/xxxxx/chromedriver");
DesiredCapabilities cap = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9515/wd/hub), cap);
driver.get("http://www.google.com");

代码可以编译和执行,但是Chrome永远不会出现。我没有任何错误。请注意,我正在localhost上启动RemoteWebDriver,而Chrome仍然无法正常工作。如果将URL更改为Windows PC的IP,则没有任何改变。我在RemoteWebDriver上做错了什么,或者我需要将参数传递给ChromeDriver。请帮忙。

最佳答案

经过更多搜索后找到了答案。事实证明remotewebdriver的URL只需要是localhost:9515而不是/wd/hub。另外,如果在另一台计算机上运行,​​请确保在该计算机上启动chromedriver,并将webdriver.chrome.driver指向chromedriver的位置。

关于java - 将Selenium 2 RemoteWebDriver与ChromeDriver结合使用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9542020/

10-09 08:11