简体   繁体   English

将Selenium 2 RemoteWebDriver与ChromeDriver结合使用

[英]Using Selenium 2 RemoteWebDriver with ChromeDriver

I searched for an answer to my question here and on the web but couldn't find anything that was helpful to me. 我在这里和网络上搜索了我的问题的答案,但找不到任何对我有帮助的东西。 Hopefully this isn't too dumb of a question. 希望这不是一个愚蠢的问题。

I'm trying to get Selenium 2 to work using various browsers. 我正在尝试让Selenium 2使用各种浏览器工作。 I am using a Mac as a hub and a node and a Windows pc as a node. 我使用Mac作为集线器和节点,并使用Windows pc作为节点。 My problem is with Chrome. 我的问题是Chrome。 I want to initiate the Java code on the Mac and have the Selenium tests run on the Windows pc. 我想在Mac上启动Java代码,并在Windows pc上运行Selenium测试。 To get Chrome to run on localhost I have the following code: 要使Chrome在本地主机上运行,​​我需要以下代码:

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

This opens up Chrome on the hub/node Mac. 这会在中心/节点Mac上打开Chrome。 How do I get it to open up on the Windows PC? 如何在Windows PC上打开它? Can I pass anything into the ChromeDriver() class? 我可以将任何东西传递给ChromeDriver()类吗?

I've tried using RemoteWebDriver, and have the following: 我尝试使用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");

The code compiles and executes, but Chrome never comes up. 代码可以编译和执行,但是Chrome永远不会出现。 I don't get any errors. 我没有任何错误。 Note that I'm initiating the RemoteWebDriver on localhost and Chrome still doesn't work. 请注意,我正在localhost上启动RemoteWebDriver,而Chrome仍然无法正常工作。 Nothing changes if I change the URL to the IP of the Windows PC. 如果将URL更改为Windows PC的IP,则没有任何改变。 I'm either doing something wrong with the RemoteWebDriver or I need to pass parameters to ChromeDriver. 我在RemoteWebDriver上做错了事,或者我需要将参数传递给ChromeDriver。 Please help. 请帮忙。

Found the answer after a bit more searching. 经过更多搜索后找到了答案。 Turns out that the URL of the remotewebdriver needed to be only localhost:9515 without /wd/hub . 事实证明remotewebdriver的URL仅需为localhost:9515而无需/wd/hub Also, if running on another machine, make sure to start up chromedriver on that machine and point webdriver.chrome.driver to the location of chromedriver. 另外,如果在另一台计算机上运行,​​请确保在该计算机上启动chromedriver,并将webdriver.chrome.driver指向chromedriver的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM