我正在尝试使用webdriver.execute_script函数运行一些javascript,如下所示:
self.webdriver.execute_script("var btn = document.getElementsByClassName('_3XJPq')[0]; btn.disabled=true; btn.innerHTML='Perform Review'")
但是,我收到以下错误:
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 491, in execute_script
'args': converted_args})['value']
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 254, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/remote_connection.py", line 487, in _request
self._conn.request(method, parsed_url.path, body, headers)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1250, in _send_request
self.putrequest(method, url, **skips)
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/http/client.py", line 1108, in putrequest
raise CannotSendRequest(self.__state)
http.client.CannotSendRequest:请求发送
基于之前的一些问题(httplib CannotSendRequest error in WSGI),似乎连接已断开,我在尝试重用它时失败了。有没有办法在selenium中创建新的连接而无需离开页面?
如果有帮助,我正在使用chrome webdriver。
谢谢!