问题
- 通过
selenium-server-standalone
注册node后,启动driver.get()报错
- github:issues: https://github.com/SeleniumHQ/selenium/issues/8326
代码区
from selenium.webdriver import Remote
import time
driver = Remote(
command_executor='http://192.168.171.1:5555/wd/hub',
desired_capabilities={
'browserName': 'chrome',
'platform': 'ANY',
'version': '',
'javascriptEnabled': True
}
)
driver.get('http://www.baidu.com')
driver.find_element_by_id('kw').send_keys('hwijew')
driver.find_element_by_id('su').click()
time.sleep(3)
driver.quit()
控制台错误信息
Traceback (most recent call last):
File "/selenium4.py", line 7, in <module>
driver.get("http://www.google.com")
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 333, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 208, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Host header or origin header is specified and is not localhost.
解决办法
- 重新下载
selenium-server-standalone
版本规定到3.141.1.jar, http://selenium-release.storage.googleapis.com/index.html?path=3.141/
- selenium版本锁定==3.141.0版本
- 使用教程参考博客:https://blog.csdn.net/hwijew/article/details/120548305