问题描述
我想使用 phantomJS
进行一些网络测试,我遇到了 GhostDriver
()。我使用自述文件中的说明构建它,我可以在指定的端口上运行它,但我不知道如何从我的Java代码访问Web驱动程序。为了澄清,我在ruby中看到了这个例子:
I want to use phantomJS
for some web testing, and I've come across GhostDriver
(https://github.com/detro/ghostdriver). I've built it using the instructions in the readme and I can run it on a specified port, but I am not sure how to access the web driver from my java code. To clarify, I've seen this example in ruby:
caps = {
:browserName => "phantomjs",
:platform => "LINUX"
}
urlhub = "http://key:[email protected]:4444/wd/hub"
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 120
@webdriver = Selenium::WebDriver.for :remote, :url => urlhub, :desired_capabilities => caps, :http_client => client
@webdriver.navigate.to "http://www.google.com/"
puts @webdriver.title
@webdriver.save_screenshot("./screenshot.png")
@webdriver.quit
我只是不确定如何从java做同样的事情。
I'm just not sure how to do the same from java.
推荐答案
我相信这个链接会回答你的问题。你需要Selenium 2.28.0和PhantomJS 1.8。我已经对此进行了测试,虽然我的测试是前瞻性的,但它的工作方式与广告一样。请注意,您需要下载Selenium zip文件以获取包含绑定的jar。 Maven回购还没有包含它。
I believe this link will answer your questions. You will need Selenium 2.28.0, and PhantomJS 1.8. I have tested this, and it works as advertised, although my tests were precursory. Note that you need to download the Selenium zip file to get the jar which contains the bindings. The Maven repo does not yet include it.
这篇关于如何使用java运行Selenium的ghostdriver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!