I am running Python 2.7 under Ubuntu 14.04 environment. Usually my selenium works great and I used to code with that. My PC have never been touched for 4 months and I come back to code and find this error. Not sure what should I do.
The code is extremely simple:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import sys
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
driver1 = webdriver.Firefox()
driver1.get("https://www.google.com")
And it brought up this error:
*File "/home/luke/python/gmail registry", line 11, in <module>
driver1 = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 103, in __init__
self.binary, timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 51, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 106, in _wait_until_connectable
% (self.profile.path))
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: /tmp/tmp_W4qvw If you specified a log_file in the FirefoxBinary constructor, check it for details.*
I also tried use:
driver1 = webdriver.Chrome()
driver1.get("https://www.google.com")
And it turned out to be:
*File "/home/luke/python/gmail registry", line 11, in <module>
driver1 = webdriver.Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 67, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 91, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 173, in start_session
'desiredCapabilities': desired_capabilities,
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 231, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 395, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 426, in _request
resp = self._conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1089, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 444, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 408, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''*
Thanks a lot! This really confused me.
My selenium is 2.53.1
You could try to specify the path to your webdriver's exe like this :
driver1 = webdriver.Chrome('{path to your driver parent folder}/chromedriver.exe')
Related
On Replit normal selenium works fine but undetected chromedriver (the python library) doesn't seem to work, here's my code:
import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://google.com')
I keep getting this error:
Traceback (most recent call last):
File "main.py", line 4, in <module>
driver = uc.Chrome()
File "/home/runner/fff/venv/lib/python3.8/site-packages/undetected_chromedriver/__init__.py", line 401, in __init__
super(Chrome, self).__init__(
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
self.service.start()
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/runner/fff/venv/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 110, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service /home/runner/.local/share/undetected_chromedriver/9366826a81e09122_chromedriver unexpectedly exited. Status code was: 127
Does anyone know how to fix it? Please help, thanks so much!
/usr/local/bin/python3.9 /Users/rabbu/PycharmProjects/pythonProject/seleniumpkg/Basic.py
Traceback (most recent call last):
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/common/service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 947, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py", line 1819, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '../drivers.chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/rabbu/PycharmProjects/pythonProject/seleniumpkg/Basic.py", line 4, in <module>
driver = webdriver.Chrome(executable_path="../drivers.chromedriver")
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/rabbu/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/common/service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'drivers.chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
You can use webdriver_manager to directly download and launch the driver without providing the path.
You can install by using webdriver_manager by using pip3 install webdriver_manager
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())
driver.get("Your URL")
I am attempting to automate a web browser using the environment below:
Windows10, Selenium (v3.141.0), Python (v3.7.4) chrome (v77.0.3865.90), and chromedriver (v77.0.3865.40). I installed pip, installed Selenium(using Python), set my paths in the environmental variables, called out the path to my chromedriver, and I still am running into issues.
-path using for chromedriver: "C:\webdrivers\chromedriver.exe"
-path to Python: "C:\Users\linds\AppData\Local\Programs\Python\Python37"
I have some code that I ran below with errors. Any ideas?
>>> from selenium import webdriver
>>> from selenium.webdriver.chrome.options import Options
>>> options = Options()
>>> options.add_argument('--headless')
>>> options.add_argument('--no-sandbox')
>>> options.add_argument('--disable-gpu')
>>> driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
Traceback (most recent call last):
File "<pyshell#31>", line 1, in <module>
driver = webdriver.Chrome(options=options, executable_path='C:\webdrivers\chromedriver.exe')
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\linds\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process.
When attempting to run Selenium Webdriver tests with IE, the browser will launch but immediately crash with the error "Command line server for the IE driver has stopped working".
The scripts where IE fails run just fine in Chrome and Firefox.
Windows 10 IE 11.15.16299.0
Python 3.6.3 (tried with Python 2.7.14)
32-bit IEDriverServer.exe version 3.5.0.0
I followed the setup instructions at
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
Here's what Python reports:
Traceback (most recent call last):
File "tc_131.py", line 34, in <module>
driver.set_page_load_timeout(30)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 814, in set_page_load_timeout
'pageLoad': int(float(time_to_wait) * 1000)})
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute
response = self.command_executor.execute(driver_command, params)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 464, in execute
return self._request(command_info[0], url, body=data)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 526, in _request
resp = opener.open(request, timeout=self._timeout)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1321, in do_open
r = h.getresponse()
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse
response.begin()
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin
version, status, reason = self._read_status()
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "C:\Users\brent\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto
return self._sock.recv_into(b)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
The simplest test causes the failure:
from selenium import webdriver
driver = webdriver.Ie()
driver.set_page_load_timeout(30)
driver.get('https://google.com')
driver.implicitly_wait(30)
I had the similar problem yesterday:
At first I tried to run with 64-bit IEDriverServer.exe version 3.9.0.0 and also had ConnectionResetError: [WinError 10054]
And then I download 32-bit IEDriverServer 3.9 from here https://www.seleniumhq.org/download/
And my script now is working and IE runs good (even without setting "executable_path" (added to PATH) and time sleeping):
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
#driver = webdriver.Ie(executable_path="C:\\webdrivers\\IEDriverServer.exe")
driver = webdriver.Ie()
#driver.set_script_timeout(5.0)
#time.sleep(3)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
time.sleep(5)
driver.close()
Maybe, you need update version of IEDriverServer to 3.9
And my python version is higher 3.6.5
Also I added both register keys (for 32-bit and 64-bit path) as mentioned in the setup instruction:
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
I hope this will help...
I had a similar problem but I am using c# had a read here https://github.com/SeleniumHQ/selenium/issues/6085 and this solved my problem You might need to read through the discussion
driver.FindElement(By.XPath("(//input[#id='Submit'])[2]")).Click();
My understanding is in IE the above syntax is not working but you might want to use this instead
IWebElement submit = driver.FindElement(By.XPath("(//input[#id='Submit'])[2]"));
OpenQA.Selenium.Interactions.Actions buildersub = new OpenQA.Selenium.Interactions.Actions(driver);
OpenQA.Selenium.Interactions.Actions hoverClicksub = buildersub.MoveToElement(submit).MoveByOffset(5, 5).Click();
hoverClicksub.Build().Perform();
I'm getting the following error from selenium:
File "clint-selenium.py", line 58, in <module>
browser = Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 234, in execute
response = self.command_executor.execute(driver_command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 407, in execute
return self._request(command_info[0], url, body=data)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/remote_connection.py", line 439, in _request
resp = self._conn.getresponse()
File "/usr/lib/python2.7/httplib.py", line 1136, in getresponse
response.begin()
File "/usr/lib/python2.7/httplib.py", line 453, in begin
version, status, reason = self._read_status()
File "/usr/lib/python2.7/httplib.py", line 417, in _read_status
raise BadStatusLine(line)
httplib.BadStatusLine: ''
I am calling it with code:
from contextlib import closing
from selenium.webdriver import Chrome # pip install selenium
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
browser = Chrome()
browser.get('http://www.google.com')
time.sleep(1)
print browser.title
browser.quit()
I have evidently done something to my laptop because this used to work. Any thoughts
EDIT
I've tried updating chromedriver but I'm now getting
Traceback (most recent call last):
File "clint-selenium.py", line 58, in <module>
browser = Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: session not created exception
from unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"13524.1","isDefault":true},"id":1,"name":"","origin":"://"}
(Session info: chrome=54.0.2840.90)
(Driver info: chromedriver=2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b),platform=Linux 4.4.0-45-generic x86_64)
This seems to indicate I'm still not using the latest version. I've followed a couple of guides about installation and I'm getting the same result. Any thoughts
Chromedriver was apparently updated on 2016-10-22, after which I also encountered this problem. Updating to the new version of Chromedriver (2.25) fixed it for me.