Python selenium script can't connect to browser - python

Example
This is a script that should be able to connect to the browser that was launched with debug options in the command prompt. As I provide later I'm no longer able to connect to the remote browser at 127.0.0.1:9222." I've tried searching for a solution, but I haven't found one that works.
Launching browser in with debug port
"c:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --remote-debugging-port=9222
Python script
from selenium import webdriver
from selenium.webdriver.edge.options import Options
edge_options = Options()
edge_options.add_experimental_option('debuggerAddress', '127.0.0.1:9222')
driver = webdriver.Edge(options=edge_options)
driver.get(youtube.com)
printf(driver.title)
Problem
For some reason, my code can no longer connect to the browser launched by the command mentioned. This is an error message Im facing.
part of the error message
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to microsoft edge at 127.0.0.1:9222 **from chrome not reachable **
full error message
Traceback (most recent call last):
File "C:\Users\user\OneDrive\Plocha\záložky\msedge - running\Try 18.py", line 7, in <module>
driver = webdriver.Edge(options=edge_options)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\edge\webdriver.py", line 73, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot connect to microsoft edge at 127.0.0.1:9222
from chrome not reachable
Stacktrace:
Backtrace:
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF72EE616C2+15186]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EDFA212+827554]
(No symbol) [0x00007FF72EABEBF3]
(No symbol) [0x00007FF72EAAEC8A]
(No symbol) [0x00007FF72EAF013D]
(No symbol) [0x00007FF72EAE5D4A]
(No symbol) [0x00007FF72EB29C56]
(No symbol) [0x00007FF72EB21D23]
(No symbol) [0x00007FF72EAF3B80]
(No symbol) [0x00007FF72EAF2B0E]
(No symbol) [0x00007FF72EAF4344]
Microsoft::Applications::Events::EventProperties::SetProperty [0x00007FF72ECDC3B0+182752]
(No symbol) [0x00007FF72EBB0095]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72ED3A6EA+42362]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72ED3D425+53941]
Microsoft::Applications::Events::ILogManager::DispatchEventBroadcast [0x00007FF72F058AB3+1456595]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE0276A+861690]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE07854+882404]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE079AC+882748]
Microsoft::Applications::Events::EventProperty::EventProperty [0x00007FF72EE1097E+919566]
BaseThreadInitThunk [0x00007FF8D3C726BD+29]
RtlUserThreadStart [0x00007FF8D5A6DFB8+40]
What have I tried?
There are many tutorials on using python and chrome, but not many are for an edge. Here are some samples of things I've tried:
https://www.youtube.com/watch?v=Zrx8FSEo9lk
https://www.youtube.com/watch?v=FGaU0OgtbNk&t=181s
https://www.youtube.com/watch?v=pZdMsLKAjs4&t=271s
https://bugs.chromium.org/p/chromedriver/issues/detail?id=710#c3
https://www.geeksforgeeks.org/automated-browser-testing-with-edge-and-selenium-in-python/
https://stackoverflow.com/questions/8344776/can-selenium-interact-with-an-existing-browser-session
Be patient, thanks.

Related

I can't access the Add comment on instagram item. Python

I'm trying to automate comments on an Instagram post using Python and Selenium. I am trying to access the text area where you write comments in all possible ways, such as CLASS_NAME, TAG_NAME, XPATH, CSS_SELECTOR. However, none of these methods are working. I have also tried using the implicit wait method to make sure the element is loaded, but that doesn't work either. I'm not sure what the problem is. I just need someone to tell me how to access the element where comments are written on an instagram post, send a send_keys to that element and hit the submit button.
The current status of the code is this:
from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import json
import os
import pickle
from selenium import __version__
data = {
'username' : 'wendyturner329ysu',
'password' : 'MpEgPAhd',
'url_publication' : 'https://www.instagram.com/p/ClZj_e4vZCF/',
'comment' : 'This is an automated comment!',
'time' : 3
}
def Comments():
driver = webdriver.Chrome()
driver.get("https://www.instagram.com")
cookies = pickle.load(open("cookies.pkl", "rb"))
for cookie in cookies:
if cookie['domain'] == ".instagram.com":
try:
driver.add_cookie(cookie)
except Exception as e:
print(e)
driver.get("https://www.instagram.com/p/ClZj_e4vZCF/")
time.sleep(4)
driver.find_element(By.XPATH, '//textarea[#aria-label="Add a comment..."]').send_keys(data['comment'])
time.sleep(5)
Comments()
The error it throws is:
C:\Users\54225\AppData\Local\Programs\Python\Python310\python.exe C:/Users/54225/Documentos/Proyecto/Comentarios_Instagram_Selenium.py
Traceback (most recent call last):
File "C:\Users\54225\Documentos\Proyecto\Comentarios_Instagram_Selenium.py", line 39, in <module>
Comentarios()
File "C:\Users\54225\Documentos\Proyecto\Comentarios_Instagram_Selenium.py", line 36, in Comentarios
driver.find_element(By.XPATH, '//textarea[#aria-label="Agrega un comentario..."]').send_keys(datos['comentario'])
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 233, in send_keys
self._execute(
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 410, in _execute
return self._parent.execute(command, params)
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=109.0.5414.75)
Stacktrace:
Backtrace:
(No symbol) [0x00F36643]
(No symbol) [0x00ECBE21]
(No symbol) [0x00DCDA9D]
(No symbol) [0x00DD09E4]
(No symbol) [0x00DD08AD]
(No symbol) [0x00DD0B30]
(No symbol) [0x00DFC474]
(No symbol) [0x00DFB7AB]
(No symbol) [0x00E1FD7C]
(No symbol) [0x00DF641F]
(No symbol) [0x00E200D4]
(No symbol) [0x00E36B09]
(No symbol) [0x00E1FB76]
(No symbol) [0x00DF49C1]
(No symbol) [0x00DF5E5D]
GetHandleVerifier [0x011AA142+2497106]
GetHandleVerifier [0x011D85D3+2686691]
GetHandleVerifier [0x011DBB9C+2700460]
GetHandleVerifier [0x00FE3B10+635936]
(No symbol) [0x00ED4A1F]
(No symbol) [0x00EDA418]
(No symbol) [0x00EDA505]
(No symbol) [0x00EE508B]
BaseThreadInitThunk [0x7612FEF9+25]
RtlGetAppContainerNamedObjectPath [0x770A7BBE+286]
RtlGetAppContainerNamedObjectPath [0x770A7B8E+238]
Process finished with exit code 1
When I use implicity wait this happens, this is the code:
datos = {
'usuario' : 'wendyturner329ysu',
'contraseña' : 'MpEgPAhd',
'url_publicacion' : 'https://www.instagram.com/p/ClZj_e4vZCF/',
'comentario' : 'Este es un comentario automatizado!',
'tiempo' : 3
}
def Comentarios():
"""Lo que esta comentado es para usar un proxy especifico"""
#proxy = "136.228.220.49:8082"
#options = webdriver.ChromeOptions()
#options.add_argument('--proxy-server=%s' % proxy)
#driver = webdriver.Chrome(chrome_options=options)
driver = webdriver.Chrome()
driver.get("https://www.instagram.com")
cookies = pickle.load(open("cookies.pkl","rb"))
for cookie in cookies:
if cookie['domain'] == ".instagram.com":
try:
driver.add_cookie(cookie)
except Exception as e:
print(e)
driver.get("https://www.instagram.com/p/ClZj_e4vZCF/")
time.sleep(4)
wait = WebDriverWait(driver, 10)
comment_box = wait.until(EC.presence_of_element_located((By.XPATH, '//textarea[#aria-label="Agrega un comentario..."]')))
comment_box.send_keys(datos['comentario'])
And give me this error:
Traceback (most recent call last):
File "C:\Users\54225\Documentos\Proyecto\Comentarios_Instagram_Selenium.py", line 42, in <module>
Comentarios()
File "C:\Users\54225\Documentos\Proyecto\Comentarios_Instagram_Selenium.py", line 38, in Comentarios
comment_box.send_keys(datos['comentario'])
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 233, in send_keys
self._execute(
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webelement.py", line 410, in _execute
return self._parent.execute(command, params)
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\54225\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=109.0.5414.75)
Stacktrace:
Backtrace:
(No symbol) [0x00F36643]
(No symbol) [0x00ECBE21]
(No symbol) [0x00DCDA9D]
(No symbol) [0x00DD09E4]
(No symbol) [0x00DD08AD]
(No symbol) [0x00DD0B30]
(No symbol) [0x00DFC474]
(No symbol) [0x00DFB7AB]
(No symbol) [0x00E1FD7C]
(No symbol) [0x00DF641F]
(No symbol) [0x00E200D4]
(No symbol) [0x00E36B09]
(No symbol) [0x00E1FB76]
(No symbol) [0x00DF49C1]
(No symbol) [0x00DF5E5D]
GetHandleVerifier [0x011AA142+2497106]
GetHandleVerifier [0x011D85D3+2686691]
GetHandleVerifier [0x011DBB9C+2700460]
GetHandleVerifier [0x00FE3B10+635936]
(No symbol) [0x00ED4A1F]
(No symbol) [0x00EDA418]
(No symbol) [0x00EDA505]
(No symbol) [0x00EE508B]
BaseThreadInitThunk [0x7612FEF9+25]
RtlGetAppContainerNamedObjectPath [0x770A7BBE+286]
RtlGetAppContainerNamedObjectPath [0x770A7B8E+238]
As I can see in your code, you have import for WebDriverWait but you are not using it. You can try below solution.
wait = WebDriverWait(driver, 10)
comment_box = wait.until(EC.presence_of_element_located((By.XPATH, '//textarea[#aria-label="Add a comment..."]')))
comment_box.send_keys(data['comment'])
OR
comment_box = driver.execute_script("return document.querySelector('textarea[aria-label=\"Add a comment...\"]');")
comment_box.send_keys(data['comment'])

My selenium code throwing error while using opera browser for the first time

I am using opera version=91.0.4516.16 and operadriver version = 105.0.5195.102.
I'm unable to opera browser with the simplest code also which is:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
s = Options()
s.binary_location = r'C:\Users\Admin\AppData\Local\Programs\Opera\launcher.exe'
driver = webdriver.Opera( executable_path=r'F:\ffmpeg\bin\operadriver.exe')
driver.get("http://google.com/")
I have used varied combination of codes but the same error occurs again and again.
ERROR IS:
Traceback (most recent call last):
File "r:\Youtube\operatest.py", line 96, in <module>
driver = webdriver.Opera( executable_path=r'F:\ffmpeg\bin\operadriver.exe')
File "R:\avirtual\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 75, in __init__
OperaDriver.__init__(self, executable_path=executable_path,
File "R:\avirtual\lib\site-packages\selenium\webdriver\opera\webdriver.py", line 51, in __init__
ChromiumDriver.__init__(self,
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "R:\avirtual\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
RemoteWebDriver.__init__(
File "R:\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 275, in __init__
self.start_session(capabilities, browser_profile)
File "R:\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "R:\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "R:\avirtual\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: Missing or invalid capabilities
(Driver info: operadriver=105.0.5195.102 (4c16f5ffcc2da70ee2600d5db77bed423ac03a5a-refs/branch-heads/5195_55#{#4}),platform=Windows NT 10.0.19042 x86_64)
Edit 2:
After changing my code. WHich is:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.opera import OperaDriverManager
# from selenium.webdriver.opera.options import Options
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.add_experimental_option('w3c', True)
options.binary_location = r"C:\Users\Admin\AppData\Local\Programs\Opera\launcher.exe"
driver = webdriver.Chrome(executable_path=OperaDriverManager().install(), options=options)
driver.get("https://www.google.com")
The Error is:
r:\google_account_Maker\Youtube_channels_maker\operatest.py:120: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=OperaDriverManager().install(), options=options)
Traceback (most recent call last):
File "r:\google_account_Maker\Youtube_channels_maker\operatest.py", line 120, in <module>
driver = webdriver.Chrome(executable_path=OperaDriverManager().install(), options=options)
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
RemoteWebDriver.__init__(
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 275, in __init__
self.start_session(capabilities, browser_profile)
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 365, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "R:\google_account_Maker\avirtual\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Opera failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from opera location C:\Users\Admin\AppData\Local\Programs\Opera\launcher.exe is no longer running, so OperaDriver is assuming that Opera has crashed.)
Stacktrace:
Backtrace:
Ordinal0 [0x00007FF69BAE84A2+2720930]
Ordinal0 [0x00007FF69BA5EF02+2158338]
Ordinal0 [0x00007FF69B939637+955959]
Ordinal0 [0x00007FF69B961D71+1121649]
Ordinal0 [0x00007FF69B95CF6A+1101674]
Ordinal0 [0x00007FF69B99A829+1353769]
Ordinal0 [0x00007FF69B994B63+1330019]
Ordinal0 [0x00007FF69B967E6C+1146476]
Ordinal0 [0x00007FF69B969298+1151640]
GetHandleVerifier [0x00007FF69BDFD5F8+3154216]
GetHandleVerifier [0x00007FF69BDEE40D+3092285]
GetHandleVerifier [0x00007FF69BB9488C+627644]
GetHandleVerifier [0x00007FF69BB93643+622963]
Ordinal0 [0x00007FF69BA67DDF+2194911]
Ordinal0 [0x00007FF69BA6D284+2216580]
Ordinal0 [0x00007FF69BA6D3FB+2216955]
Ordinal0 [0x00007FF69BA79F30+2268976]
BaseThreadInitThunk [0x00007FF804EC7034+20]
RtlUserThreadStart [0x00007FF8069C2651+33]
I can't understand why the opera browseris crashing again and again. Please help me to understand.
Solution
With selenium==4.2.0
You can solve your issue.
Also one more thing, the reason why we can't use opera in our latest version of selenium is that opera don't follow the rules of w3 that's why it was removed by selenium
from webdriver_manager.opera import OperaDriverManager
from selenium import webdriver
options = webdriver.ChromeOptions()
opera_profile = r"C:\\Users\\LEGEND\\AppData\\Roaming\\Opera Software\\Opera Stable"
options.add_argument('user-data-dir=' + opera_profile)
options._binary_location = r'C:\\Users\\LEGEND\\AppData\\Local\\Programs\\Opera\\launcher.exe'
options = webdriver.ChromeOptions()
options.add_argument('allow-elevated-browser')
options.add_experimental_option('w3c', True)
driver = webdriver.Opera(executable_path=OperaDriverManager().install(), options=options)
driver.get('https://whatsmyip.com')
driver.quit()
I Hope it resolves your issue to use operadriver.exe
Solution
With selenium4 as the key executable_path is deprecated you have to use an instance of the Service() class along with ChromeDriverManager().install() command as discussed below.
Pre-requisites Ensure that:
Selenium is upgraded to v4.0.0
pip3 install -U selenium
Webdriver Manager for Python is installed
pip3 install webdriver-manager
Selenium v4 compatible Code Block
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.google.com")
Added the answer for Chrome, make sure to change for opera.

selenium.common.exceptions.SessionNotCreatedException: Message: session not created, selenium python

I have a problem, every, single, TIME
Basically this is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\Program Files (x86)\Google\Chrome Beta\Application\chrome.exe"
options.add_argument("--no-sandbox")
options.add_argument("--no-default-browser-check")
options.add_argument("--no-first-run")
options.add_argument("--disable-default-apps")
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
driver.get('https://www.youtube.com/')
and the error is
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
I used Pycharm and tried to use VS code with python 3.4 and 3.7 and 3.8.3
plz help me I'm getting tired of this.
Full error Log:
Traceback (most recent call last):
File "C:/Users/um/PycharmProjects/Selenium/main.py", line 10, in <module>
driver = webdriver.Chrome(options=options, executable_path="C:\Program Files (x86)\Google\Chrome Beta\Application\chromedriver.exe")
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\um\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
from disconnected: unable to send message to renderer
(Session info: chrome=81.0.4044.83)
Your error is not
unable to send message to renderer
as you mentioned. According to the stack trace you posted the problem in the line 6
driver = webdriver.Chrome(options=options, executable_path="chromedriver.exe", )
and the problem is:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created
It seems like you specified an invalid path to the chromedriver and Selenium is unable to initialize the driver and create a session.
You should also check the version of the chromedriver with the guide.
Here you can download the valid version (I have taken your Chrome version from the stacktrace).
yes it did start and then close with the error log above, and also i have the correct version

Selenium WebDriverException with headless chrome [duplicate]

This question already has answers here:
WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
(44 answers)
Closed 4 years ago.
I made a python script that scrapes information and clicks a few buttons and it works great on chrome webdriver, but as soon as I try to enter it as headless it does nothing for a few seconds and then gives an error. My code is below.
options = Options()
options.headless = True
options.add_argument("user-data-dir=selenium")
browser = webdriver.Chrome(executable_path=r'C:\Users\REDACTED\Desktop\REDACTED\browser\chromedriver.exe', options=options)
browser.get('https://REDACTED')
And here's the error
Traceback (most recent call last):
File "C:/Users/REDACTED/PycharmProjects/Test/REDACTED.py", line 49, in <module>
browser = webdriver.Chrome(executable_path=r'C:\Users\REDACTED\Desktop\REDACTED\browser\chromedriver.exe', options=options)
File "C:\Users\REDACTED\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\REDACTED\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\REDACTED\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\REDACTED\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\REDACTED\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: DevToolsActivePort file doesn't exist
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)
What works for me when I use selenium with chrome is:
you can try options.add_argument('--headless') as your method brings up an error (only for chrome, no error for firefox)
another thing you can try is removing the .exe from your executable_path. When i add .exe i get a the same error you got.

Selenium chromedriver 2.25 TimeoutException cannot determine loading status

I am using python3 on mac os and I have updated chrome, chromedriver and selenium to the latest version. I am getting a TimeoutException, the browser opens correctly but it freezes.
>>> from selenium import webdriver
>>> driver = webdriver.Chrome()
# opens browser with blank page
>>> driver.get('http://example.com')
# gets first page OK and then driver literally flashes once
>>> driver.get('http://stackoverflow.com')
>>>
# Cursor loading forever... until TimeoutException
This error is thrown:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -0.003
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.0 x86_64)
I'm using: Python 3.5.2 ,Chrome 54.0, chromedriver 2.25, selenium 3.0.1
I've tried other versions of chromedriver with no success, also I did not find any solution to this online. Thanks.
EDIT:
Still getting the error from above + getting a new error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/site-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: bad inspector message: {"method":"Page.loadEventFired","params":{"timestamp":14220,088073}}
(Session info: chrome=54.0.2840.71)
(Driver info: chromedriver=2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1),platform=Mac OS X 10.12.0 x86_64)
selenium.common.exceptions.TimeoutException: Message: timeout: cannot determine loading status
from timeout: Timed out receiving message from renderer: -0.003
Issue817:It looks like this issue has been logged as a bug for Selenium.
Someone has answered to get rid from this issue by using the --dns-prefetch-disable option of chrome.
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--dns-prefetch-disable')
driver = Chrome(chrome_options=chrome_options)
If issue still exists follow this thread may be it solves your problem
Set
env LANG=en_US.UTF-8 ./chromedriver
from : https://bugs.chromium.org/p/chromedriver/issues/detail?id=1552

Categories

Resources