ore*_*tin 8 selenium python-3.x
我是selenium webdriver的新手.我写了一个单元测试脚本并在2台不同的Windows 10机器上运行它.在第一台机器上,代码运行没有任何错误.当我在第二台机器上运行代码时,代码被执行,我可以看到所有测试都通过了,但我仍然收到以下错误:"试图运行命令而不建立连接"
这是什么原因,我该如何解决这个问题?谢谢
我可以在缝纫箱外自由地说话吗?对于 Selenium,我推荐 Linux(因为你可以使用crontab -e以下脚本)、Google Chrome 和 chromedriver。它工作得很好,特别是如果您想测量加载时间。PhantomJS 有时会被秒掉,不会进一步开发 IIRC。这是我未经测试的示例:
# -*- coding: utf-8 -*-
import datetime
import os
# from pushbullet import Pushbullet
import pytz
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# api_key = '<BLAHBLAHBLAH>'
# pb = Pushbullet(api_key)
d = pytz.timezone('Europe/Berlin').localize(datetime.datetime.now().replace(microsecond=0)).isoformat()
ok = True
ttfb = -1
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.binary_location = r'<PATH_TO_CHROME>'
webdriver = webdriver.Chrome(executable_path=r'<PATH_TO_CHROMEDRIVER>', chrome_options=chrome_options)
try:
webdriver.get('https://www.example.com/')
print(webdriver.execute_script('return performance'))
ttfb = webdriver.execute_script('return (performance.timing.responseStart - performance.timing.navigationStart)')
assert 'Example' in webdriver.find_element_by_css_selector("BODY").text
except (KeyboardInterrupt, MemoryError, SyntaxError, SystemExit):
raise
except Exception as e:
ok = False
# push = pb.push_note('Something went wrong.', '<BLAHBLAH>' + '\n\Date: ' + d, channel=pb.get_channel('channel-has-to-be-created'))
try:
webdriver.quit()
except (KeyboardInterrupt, MemoryError, SyntaxError, SystemExit):
raise
except Exception as e:
pass
print(d)
print(ok)
print(ttfb)
Run Code Online (Sandbox Code Playgroud)
如果有什么不清楚的地方,请询问。这是否能帮助您解决 Windows 问题取决于您,但也许您和其他人可以比较他们的代码并得出新的结论。玩得开心。
| 归档时间: |
|
| 查看次数: |
2293 次 |
| 最近记录: |