selenium Remote模式下报错 selenium/standalone-chrome:4.0.0: “Host header or origin header is specified and is not localhost”

问题

  1. 通过selenium-server-standalone注册node后,启动driver.get()报错
  2. 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.

解决办法

  1. 重新下载selenium-server-standalone版本规定到3.141.1.jar, http://selenium-release.storage.googleapis.com/index.html?path=3.141/
  2. selenium版本锁定==3.141.0版本
  3. 使用教程参考博客:https://blog.csdn.net/hwijew/article/details/120548305
posted @ 2023-01-03 16:51  吹神  阅读(224)  评论(0编辑  收藏  举报