来自https://www.browserstack.com/automate/python的脚本
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
desired_cap = {
'browser': 'Chrome',
'browser_version': '62.0',
'os': 'Windows',
'os_version': '10',
'resolution': '1024x768',
'name': 'Bstack-[Python] Sample Test'
}
driver = webdriver.Remote(
command_executor='http://servinc1:key@hub.browserstack.com:80/wd/hub',
desired_capabilities=desired_cap)
driver.get("http://www.google.com")
if not "Google" in driver.title:
raise Exception("Unable to load google page!")
elem = driver.find_element_by_name("q")
elem.send_keys("BrowserStack")
elem.submit()
print driver.title
driver.quit()失败了
urllib3.exceptions.MaxRetryError: urllib3.exceptions.MaxRetryError port=80):最大重试超过url: /wd/集线器/会话(由NewConnectionError引起(‘:未能建立新连接: Errno 111连接被拒绝’,)
在具有本地主机HTTP代理的系统上。代理配置为{http,https}_proxy环境变量:使用请求工作:
import requests
r = requests.get('https://api.github.com/events')允许连接到hub.browserstack.com也是有效的。
目的是将BrowserStack与本地代理一起使用。这个怎么修好的?
发布于 2019-06-26 07:14:27
因此,就目前而言,解决办法似乎是:允许与hub.browserstack.com的所有连接通过防火墙。例如。
iptables -I OUTPUT 1 -p tcp --dport 443 -d hub.browserstack.com -j ACCEPT发布于 2019-05-27 04:32:36
由于用例涉及使用代理向BrowserStack集线器发送通信量,因此需要在代码片段中指定代理详细信息,如下所示-
//Set the appropriate proxy environment variable (HTTP_PROXY if it is a HTTP proxy, HTTPS_PROXY if it is a HTTPS proxy, etc.) before running the tests.
//You can set this as follows:
export HTTP_PROXY='http://<proxyhost>:<proxyport>'你可以在这里读到更多- https://www.browserstack.com/automate/python#proxy。
发布于 2022-04-04 12:45:07
在为python安装依赖库时,您可以使用urllib3==1.24.3,它应该可以工作。
pip install urllib3==1.24.3注意:这个版本的urllib3与selenium 4不兼容
https://stackoverflow.com/questions/56315169
复制相似问题