如何使用Java中的Selenium Grid启动Chrome(正常和隐身模式)并在远程PC(节点)中打开URL? [英] How to start Chrome (both normal & incognito modes) and open URL in remote PC (node) using Selenium Grid in Java?
本文介绍了如何使用Java中的Selenium Grid启动Chrome(正常和隐身模式)并在远程PC(节点)中打开URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试Java中的Selenium Grid,只想同时启动Chrome
I am trying Selenium Grid in Java and just want to start Chrome in both
- 普通模式和
- 隐身模式
在远程PC(节点)中,然后打开google.com
in remote PC (node) and open google.com
我已经设置了集线器-节点连接.我尝试了这段代码,但似乎是错误的.
I have setup the hub - node connection. I tried this code, but it seems to be wrong.
- 任何指导如何做到这一点?
- 如何使用
capability.setCapability()
?我找到了一些示例来启动IE,只是替换了 InternetExplorer 与 Chrome 一起使用...不起作用.
- Any guidance how to do that?
- How to use
capability.setCapability()
? I found some example to start IE and just replaced the word InternetExplorer with Chrome ... Doesn't work.
谢谢.
不起作用的代码:
System.setProperty("webdriver.chrome.driver" , "C:/Users/chromedriver_win32/chromedriver.exe");
WebDriver driver;
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(ChromeDriver.BINARY, new File("C:\\Program Files (x86)\\chrome.exe").getAbsolutePath());
driver = new RemoteWebDriver(new URL("http://192.168.0.106:1234/wd/hub"), capability);
driver.get("http://google.com");
System.out.println(driver.getTitle());
推荐答案
**Normal mode:**
WebDriver driver;
driver=new ChromeDriver();
**incognito mode:**
WebDriver driver;
System.setProperty("webdriver.chrome.driver","C:/Users/chromedriver_win32/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("-incognito");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver=new ChromeDriver(capabilities);
这篇关于如何使用Java中的Selenium Grid启动Chrome(正常和隐身模式)并在远程PC(节点)中打开URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文