Java 如何使用硒连接到无头铬
我想使用铬无头自动测试使用硒。() 我的无头版本已经在9222上运行了。所以,如果我开了门,你会得到什么 作为下一步,我想将硒连接到无头铬。但是当我尝试的时候Java 如何使用硒连接到无头铬,java,selenium,chromium,headless,Java,Selenium,Chromium,Headless,我想使用铬无头自动测试使用硒。() 我的无头版本已经在9222上运行了。所以,如果我开了门,你会得到什么 作为下一步,我想将硒连接到无头铬。但是当我尝试的时候 final DesiredCapabilities caps = DesiredCapabilities.chrome(); final WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9222/json"), caps); driver.get("http
final DesiredCapabilities caps = DesiredCapabilities.chrome();
final WebDriver driver = new RemoteWebDriver(new URL("http://localhost:9222/json"), caps);
driver.get("http://www.google.com");
我确实得到以下注销
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Falling back to original OSS JSON Wire Protocol.
Jän 24, 2017 7:14:45 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFORMATION: Falling back to straight W3C remote end connection
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'Geralds-MacBook-Pro.local', ip: '192.168.0.249', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_111'
Driver info: driver.version: RemoteWebDriver
问题是:
- RemoteWebDriver是连接到headless的正确驱动程序吗 铬
- 我读过关于DevTool协议(),但我不确定如何使用selenium创建这样的客户机
- 使用Chrome DevTools works()连接铬合金无头保险柜;-)李>
- 我认为自述有点误导。您不必启动Chromium本身,您可以使用
。确保安装了chromedriver()RemoteWebDriver
- 启动chromedriver(例如
或/chromedriver
)/chromedriver--port=9515
- 然后你必须告诉chromedriver用铬代替铬
- 添加
作为附加参数--headless
final ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.setBinary("/usr/bin/chromium-browser"); chromeOptions.addArguments("--headless"); desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions); WebDriver driver = new RemoteWebDriver(url, desiredCapabilities);
在Ubuntu Linux上为我工作。Chrome 59能够创建无头实例。我试过用新的chrome驱动程序2.30安装Windows,它对我很有效
或者,如果您在本地运行,您可以这样做。在斯卡拉val chromeOptions = new ChromeOptions chromeOptions.addArguments("--headless") new ChromeDriver(chromeOptions)
如果您使用的是selenium 3+chrome驱动程序,您只需使用chrome选项并启动驱动程序即可。检查项目中的详细信息
*使用以下代码:
您将获得“无头”镀铬 *完整代码ChromeOptions options = new ChromeOptions(); options.setHeadless(true); //Set Chrome option driver = new ChromeDriver(options);
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; //import ChromeOptions public class web_crawl { private static WebDriver driver = null; public static void main(String[] args) { ChromeOptions options = new ChromeOptions(); options.setHeadless(true); driver = new ChromeDriver(options); driver.get("http://www.google.com"); //The website you want to connect to }
你让它起作用了吗?我做了一个阶段,类似于您所做的(我也使用了
),但一个月后我又回到了我的设置,它没有连接..为了让事情运行,我们切换到phantomJS。通过使用Selenium的PhantomJSDriver和WebWire协议,我们可以使用此设置。(联合国)幸运的是,我们必须再次调查,因为phantomJS维护人员即将下台/Chrome 59支持无头。这对我也有用,谢谢!现在要修复<代码>键代码转换需要X显示,请考虑使用XVFB异常!对于其他人:RemoteWebDriver
$sudo apt get install xvfb
@hkq是否有必要?因为我在没有启动chrome驱动程序的情况下运行了我的测试headlessly@Rameshwar:不需要,但建议使用。否则,您将为每个测试启动和终止一个进程。摘自chomedriver网站:“ChromeDriver类在创建时启动ChromeDriver服务器进程,并在调用quit时终止它。这可能会浪费大量时间用于大型测试套件,其中每个测试都会创建ChromeDriver实例。”$xvfb run/home/nikki/chromedriver——列入白名单的ips
chromeOptions.setBinary(System.getProperty(“chromeBinaryPath”)代码>帮助我找到路径我正在使用selenium版本3,但我看不到。setHeadless Option为此需要使用3+selileum版本
ChromeOptions options = new ChromeOptions(); options.setHeadless(true); //Set Chrome option driver = new ChromeDriver(options);
import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; //import ChromeOptions public class web_crawl { private static WebDriver driver = null; public static void main(String[] args) { ChromeOptions options = new ChromeOptions(); options.setHeadless(true); driver = new ChromeDriver(options); driver.get("http://www.google.com"); //The website you want to connect to }
- 启动chromedriver(例如