可能重复:
无法连接到chromedriver 127.0.0.1:46050(Selenium :: WebDriver :: Error :: WebDriverError)
我在亚马逊ec2 api上安装了jenkins,我正在使用jenkins进行无头黄瓜测试.
我下载了chromedriver,解压缩并将其复制到我的路径(/ usr/bin)并更改了模式:
wget http://chromium.googlecode.com/files/chromedriver_linux32_18.0.1022.0.zip
解压缩chromedriver_linux32_18.0.1022.0.zip
cp chromedriver/usr/bin
sudo chmod + x/usr/bin/chromedriver
但是当我运行我的测试(HEADLESS =真正的黄瓜功能)时,我收到此错误:
无法连接到chromedriver http://127.0.0.1:50299(Selenium :: WebDriver :: Error :: WebDriverError)
哪个chromedriver:
在/ usr/bin中/ chromedriver
哪个google-chrome:
在/ usr/bin中/谷歌铬
我的Gemfile中有无头宝石,我在env.rb中也有以下代码:
如果ENV ['HEADLESS']
require 'headless'
headless = Headless.new
headless.start
at_exit do
headless.destroy
end
end
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?有任何想法吗?
headless amazon-ec2 headless-browser jenkins selenium-chromedriver
我正在开发基于WebKit(使用C++/Qt4)和JavaScript支持的无头浏览器.这样做的主要目的是能够在很大程度上基于JavaScript生成HTML网站的spanshot(参见Backbone.js或任何其他JavaScript MVC).
我知道没有任何方法可以知道页面何时被完全加载(请参阅此问题),因此,在我获得loadFinished信号(此处的文档)后,我创建了一个计时器并开始轮询DOM内容(如检查每个X ms的DOM内容,以查看是否有任何更改.如果没有我认为页面已加载并打印结果.请记住,我已经知道这不是一个接近完美的解决方案,但它是我能想到的唯一一个.如果您有任何更好的想法,请回答这个问题
注意:计时器是非阻塞的,这意味着不应以任何方式影响/阻止/暂停在WebKit中运行的所有内容.
在用一些页面测试无头浏览器之后,一切似乎都运行良好(或至少如预期的那样).但这里是heisenbug出现的地方.应该从PHP脚本调用无头浏览器,该脚本应等待(阻塞调用)某些输出,然后打印它.
在我的测试机器(Apache 2.3.14,PHP 5.4.6)上运行PHP脚本输出所需的结果,也就是说,无头浏览器获取网站,运行JavaScript并打印用户将看到的内容; 但是在生产服务器中运行相同的脚本将获取网站,运行一些 JavaScript代码并打印结果.
我可以在这里找到无头浏览器的源代码和我正在使用的PHP脚本.
注意:计时器(如无头浏览器的源代码中所示)设置为1秒,但设置更长的时间并不能解决问题
注意2:捕获所有JavaScript错误没有显示任何内容,因此不是因为缺少函数,错误的args或任何其他类型的错误代码.
我正在用2个网站测试无头浏览器. 这个是在我的测试机器和生产服务器上工作,而这个只适用于我的测试机器.
我更倾向于认为这是第二个网站中JavaScript代码中的一些奇怪的错误而不是无头浏览器的代码,因为它生成了第一个网站的完美HTML快照,但话又说回来,这是一个heisenbug所以我不确定是什么导致了这一切.
任何想法/意见将不胜感激.谢谢
我正在使用带有Python绑定的Selenium来从具有无头Firefox的网页中抓取AJAX内容.它在我的本地机器上运行时效果很好.当我在我的VPS上运行完全相同的脚本时,会在看似随机(但一致)的行上抛出错误.我的本地和远程系统具有相同的操作系统/体系结构,因此我猜测与VPS相关的区别.
对于每个回溯,该行在引发错误之前运行4次.
在执行JavaScript以将元素滚动到视图中时,我经常会遇到此URLError.
File "google_scrape.py", line 18, in _get_data
driver.execute_script("arguments[0].scrollIntoView(true);", e)
File "/home/ryne/.virtualenvs/DEV/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 396, in execute_script
{'script': script, 'args':converted_args})['value']
File "/home/ryne/.virtualenvs/DEV/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 162, in execute
response = self.command_executor.execute(driver_command, params)
File "/home/ryne/.virtualenvs/DEV/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 355, in execute
return self._request(url, method=command_info[0], data=data)
File "/home/ryne/.virtualenvs/DEV/lib/python2.7/site-packages/selenium/webdriver/remote/remote_connection.py", line 402, in _request
response = opener.open(request)
File "/usr/lib64/python2.7/urllib2.py", line 404, in open
response = self._open(req, data)
File "/usr/lib64/python2.7/urllib2.py", line 422, in _open
'_open', req)
File "/usr/lib64/python2.7/urllib2.py", line 382, in _call_chain
result = func(*args)
File "/usr/lib64/python2.7/urllib2.py", line 1214, …Run Code Online (Sandbox Code Playgroud) 是否有任何已知的适用于 Android 并支持 JS 的无头浏览器?我尝试过 HTMLUnit,但它在 Android 上不起作用。我尝试使用 JSoup,效果很好,但不支持 JS。还有其他建议吗?
我有一个工作正常的架构...基本上我的Android应用程序向node.js服务器发送一些选项,这些选项在服务器处理并获取相关数据,然后在服务器处理获取的数据通过运行phantomjs生成一个输出图像,该图像被发送回我的Android应用程序(显示在一个ImageView).远程phantomjs有效地用于代替本地浏览器(我仅限于在设备中显示输出ImageView而不是WebView直接在设备上显示输出).
但是,由于在某些情况下生成的图像可能非常大,我非常希望能够使用类似的架构(具有相同的代码库),而只是在设备上本地生成图像,而不是远程.
因此架构将是:从设备向node.js服务器发送选项(如前所述),在服务器上处理和获取相关数据(如前所述),将获取的数据发送到Android设备(新)并在Android设备上运行phantomjs以生成图像(新).
因此,"唯一"的区别实际上是我在设备上而不是在服务器上运行phantomjs.
有没有办法在Android上运行phantomjs?
实际上我试图通过selenium在远程debian服务器上运行无头浏览器.我在服务器上安装了firefox 46.0.1,我使用的是selenium 2.53.1版本.
每当我试图运行给定的测试时,我得到以下错误.
org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary(/usr/bin/firefox) on port 7055; process output follows:
Error: GDK_BACKEND does not match available displays
Run Code Online (Sandbox Code Playgroud)
我在我的代码中实例化了firefox驱动程序,如下所示:
saDriver = new FirefoxDriver();
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我想在我的 Ubuntu 16.04.1 LTS pc 上使用 --headless 选项运行 chrome,我使用 https 协议。这是命令:
$ /usr/bin/google-chrome-stable --allow-running-insecure-content --ignore-certificate-errors --disable-gpu --headless https://<APP_IP>
Run Code Online (Sandbox Code Playgroud)
这是回应:
[0718/105254.243715:ERROR:cert_verify_proc_nss.cc(923)] CERT_PKIXVerifyCert for <APP_IP> failed err=-8172
Run Code Online (Sandbox Code Playgroud)
信息:我使用谷歌浏览器 59.0.3071.115
你能给我一些绕过证书错误的建议吗?
提前谢谢
我试图让 Selenium 打开 Chrome,就像我自己打开它一样,即我应该像 Facebook 一样登录我的帐户。
我有以下代码:
def startChrome():
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")
driver = webdriver.Chrome(chrome_options=options)
driver.set_page_load_timeout(60)
return driver
driver = startChrome()
url = 'https://www.facebook.com'
driver.get(url)
Run Code Online (Sandbox Code Playgroud)
然而,这让我在没有登录的情况下进入 Facebook。我已经检查过chrome://version并且个人资料 URL 实际上是正确的。我究竟做错了什么?
使用 Python 3,Chrome 版本 63.0.3239.84,MacOS High Sierra
python selenium google-chrome headless-browser google-chrome-headless
我正在尝试在运行我的规范时模拟不同的设备,但目前没有结果。
#spec_helper
require 'rspec'
require 'capybara'
require 'capybara/rspec'
require 'selenium/webdriver'
Capybara.register_driver :headless_chrome do |app|
Capybara::Selenium::Driver.load_selenium
browser_options = ::Selenium::WebDriver::Chrome::Options.new
browser_options.args << '--headless'
mobile_emulation = { "deviceName" => "iPhone 8" }
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
"chromeOptions" => { "mobileEmulation" => mobile_emulation }
)
Capybara::Selenium::Driver.new(app, browser: :chrome, options: browser_options, desired_capabilities: capabilities)
end
Run Code Online (Sandbox Code Playgroud)
我应该mobile_emulation在选项中包含该部分而不是功能吗?
我正在尝试使用 puppeteer 发出 POST 请求并在请求中发送一个 JSON 对象,但是,我遇到了超时......如果我正在尝试发送至少得到回复的正常编码表单数据来自无效请求的服务器......这是代码的相关部分
await page.setRequestInterception(true);
const request = {"mac": macAddress, "cmd": "block"};
page.on('request', interceptedRequest => {
var data = {
'method': 'POST',
'postData': request
};
interceptedRequest.continue(data);
});
const response = await page.goto(configuration.commandUrl);
let responseBody = await response.text();
Run Code Online (Sandbox Code Playgroud)
我使用相同的代码来发出 GET 请求(没有有效负载)及其工作