Selenium python - Trying to to open chrome profile - python

I'm using the code below to try and open a specific chrome profile. Chrome starts and loads the profile but it doesn't do anything else.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#create chromeoptions instance
options = webdriver.ChromeOptions()
#provide location where chrome stores profiles
options.add_argument(r"--user-data-dir=C:\\Users\\{user name}\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument(r"--profile-directory=Profile 2")
#specify where your chrome driver present in your pc
driver = webdriver.Chrome(options=options)
#provide website url here
driver.get("https://www.google.co.in")
It also gives me the below output in the terminal.
Opening in existing browser session.
Traceback (most recent call last):
File "C:\Users\path\bot2.py", line 11, in <module>
driver = webdriver.Chrome(options=options)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\webdriver.py", line 381, 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 444, in execute
self.error_handler.check_response(response)
File "C:\Users\user\AppData\Roaming\Python\Python310\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
(No symbol) [0x00A86643]
(No symbol) [0x00A1BE21]
(No symbol) [0x0091DA9D]
(No symbol) [0x0093F2A7]
(No symbol) [0x0093A899]
(No symbol) [0x00976917]
(No symbol) [0x0097655C]
(No symbol) [0x0096FB76]
(No symbol) [0x009449C1]
(No symbol) [0x00945E5D]
GetHandleVerifier [0x00CFA142+2497106]
GetHandleVerifier [0x00D285D3+2686691]
GetHandleVerifier [0x00D2BB9C+2700460]
GetHandleVerifier [0x00B33B10+635936]
(No symbol) [0x00A24A1F]
(No symbol) [0x00A2A418]
(No symbol) [0x00A2A505]
(No symbol) [0x00A3508B]
BaseThreadInitThunk [0x753800F9+25]
RtlGetAppContainerNamedObjectPath [0x77507BBE+286]
RtlGetAppContainerNamedObjectPath [0x77507B8E+238]
I'm not sure what's wrong but it exits before opening the website.

Related

Weird Python Selenium error message when asked to find an element

I tried to find an element by class using startButton = driver.find_element(By.CLASS_NAME, "start is-armed") and I got a very weird error message. The end almost looks like it could be assembly language:
[23248:27252:0126/162232.236:ERROR:device_event_log_impl.cc(215)] [16:22:32.235] USB: usb_service_win.cc:415 Could not read device interface GUIDs: The system cannot find the file specified. (0x2)
[23248:27252:0126/162232.237:ERROR:device_event_log_impl.cc(215)] [16:22:32.238] USB: usb_device_handle_win.cc:1046 Failed to read descriptor from node connection: A device attached to the system is not functioning. (0x1F)
Traceback (most recent call last):
File "c:\Users\[myname]\OneDrive\Documents\Coding Projects\Python\learningSelenium.py", line 11, in <module>
startButton = driver.find_element(By.CLASS_NAME, "start is-armed")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 830, in find_element
return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "C:\Users\[myname]\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".start is-armed"}
(Session info: chrome=109.0.5414.120)
Stacktrace:
Backtrace:
(No symbol) [0x00F96643]
(No symbol) [0x00F2BE21]
(No symbol) [0x00E2DA9D]
(No symbol) [0x00E61342]
(No symbol) [0x00E6147B]
(No symbol) [0x00E98DC2]
(No symbol) [0x00E7FDC4]
(No symbol) [0x00E96B09]
(No symbol) [0x00E7FB76]
(No symbol) [0x00E549C1]
(No symbol) [0x00E55E5D]
GetHandleVerifier [0x0120A142+2497106]
GetHandleVerifier [0x012385D3+2686691]
GetHandleVerifier [0x0123BB9C+2700460]
GetHandleVerifier [0x01043B10+635936]
(No symbol) [0x00F34A1F]
(No symbol) [0x00F3A418]
(No symbol) [0x00F3A505]
(No symbol) [0x00F4508B]
BaseThreadInitThunk [0x762E7D69+25]
RtlInitializeExceptionChain [0x77B0BB9B+107]
RtlClearBits [0x77B0BB1F+191]
Anyone know why this is happening?
By.CLASS_NAME always accept single class value NOT multiple class values.
Instead use css selector.
startButton = driver.find_element(By.CSS_SELECTOR, ".start.is-armed")

I have multiple chrome profile and i want to open one of them

It's launch chrome profile but not able to do any action after launch chrome profile and gives error bellow.
Note: i have successfully launched chrome browser...and i want to work on my profile not on every time create new instance.
My code is this---
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
options=Options()
options.add_argument('--profile-directory=Default')
options.add_argument("user-data-dir=C:\\Users\\amit9\\AppData\\Local\\Google\\Chrome\\User Data\\")
driver = webdriver.Chrome(executable_path=(r"C:\Users\amit9\AppData\Local\Programs\Python\Python311\Scripts\chromedriver.exe"), options=options)
driver.get("https://www.google.co.in")
Error gives me after running code
PS C:\Users\amit9\OneDrive\Desktop\autogui> & C:/Users/amit9/AppData/Local/Programs/Python/Python311/python.exe c:/Users/amit9/OneDrive/Desktop/autogui/python/test.py
c:\Users\amit9\OneDrive\Desktop\autogui\python\test.py:10: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=(r"C:\Users\amit9\AppData\Local\Programs\Python\Python311\Scripts\chromedriver.exe"), options=options)
Opening in existing browser session.
Traceback (most recent call last):
File "c:\Users\amit9\OneDrive\Desktop\autogui\python\test.py", line 10, in <module>
driver = webdriver.Chrome(executable_path=(r"C:\Users\amit9\AppData\Local\Programs\Python\Python311\Scripts\chromedriver.exe"), options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\amit9\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome
has crashed.)
Stacktrace:
Backtrace:
(No symbol) [0x006BF243]
(No symbol) [0x00647FD1]
(No symbol) [0x0053D04D]
(No symbol) [0x0055C24E]
(No symbol) [0x005582E9]
(No symbol) [0x0058F056]
(No symbol) [0x0058EB2A]
(No symbol) [0x00588386]
(No symbol) [0x0056163C]
(No symbol) [0x0056269D]
GetHandleVerifier [0x00959A22+2655074]
GetHandleVerifier [0x0094CA24+2601828]
GetHandleVerifier [0x00768C0A+619850]
GetHandleVerifier [0x00767830+614768]
(No symbol) [0x006505FC]
(No symbol) [0x00655968]
(No symbol) [0x00655A55]
(No symbol) [0x0066051B]
BaseThreadInitThunk [0x76B800F9+25]
RtlGetAppContainerNamedObjectPath [0x778A7BBE+286]
RtlGetAppContainerNamedObjectPath [0x778A7B8E+238]

How to load custom profile in Chrome using Python Selenium Webdriver?

I tried to launch custom profile in chrome using python selenium webdriver.
But I met error while running. I tried arguments --no-sandbox, --disable-dev-shm-usage, --remote-debugging-port=xxxx. But not working.
Here is code.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
options = webdriver.ChromeOptions()
options.add_argument("--profile-directory=Profile 6")
options.add_argument("--user-data-dir=C:/Users/SIM/AppData/Local/Google/Chrome/User Data")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
time.sleep(3)
Here is output.
D:\me\web\fbot\src>python script_.py
Opening in existing browser session.
[7488:16428:1223/013230.522:ERROR:broker_win.cc(56)] Error reading broker pipe: The pipe has been ended. (0x6D)
Traceback (most recent call last):
File "D:\me\web\fbot\src\script_.py", line 10, in <module>
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
File "C:\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
(No symbol) [0x0103F243]
(No symbol) [0x00FC7FD1]
(No symbol) [0x00EBD04D]
(No symbol) [0x00EDC24E]
(No symbol) [0x00ED82E9]
(No symbol) [0x00F0F056]
(No symbol) [0x00F0EB2A]
(No symbol) [0x00F08386]
(No symbol) [0x00EE163C]
(No symbol) [0x00EE269D]
GetHandleVerifier [0x012D9A22+2655074]
GetHandleVerifier [0x012CCA24+2601828]
GetHandleVerifier [0x010E8C0A+619850]
GetHandleVerifier [0x010E7830+614768]
(No symbol) [0x00FD05FC]
(No symbol) [0x00FD5968]
(No symbol) [0x00FD5A55]
(No symbol) [0x00FE051B]
BaseThreadInitThunk [0x7762FA29+25]
RtlGetAppContainerNamedObjectPath [0x77CD7A7E+286]
RtlGetAppContainerNamedObjectPath [0x77CD7A4E+238]
Please help me to solve this error.
I assume your profile path is wrong,
try adding this command to your driver class:
options.add_argument("user-data-dir=/Users/alexiseggermont/Library/Application Support/Google/Chrome/Default/")
This path is usable for Mac or Linux OS. Also, rename "Default" to your profile id (for me, and in most cases, it was "Profile 1")

Selenium Chromedriver Won't Start

I'm trying to test my code using selenium with chrome driver. But I always got this error message in my terminal.
======================================================================
ERROR: test_input_status (myweb.tests.StorySixFunctionalTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/fredypasaud/Documents/PPW/story_six/myweb/tests.py", line 58, in setUp
self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/fredypasaud/Documents/PPW/django01/lib/python3.6/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: Chrome failed to start: exited normally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /snap/bin/chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
And i put my chromedriver in the same directory as the manage.py of my project. And here's some code about from my test.py
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
class StorySixFunctionalTest(TestCase):
def setUp(self):
chrome_options = Options()
self.selenium = webdriver.Chrome('./chromedriver',chrome_options = chrome_options)
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--headless')
chrome_options.add_argument('disable-gpu')
chrome_options.addArguments("--disable-extensions");
chrome_options.addArguments("--disable-dev-shm-usage");
super(StorySixFunctionalTest, self).setUp()
def tearDown(self):
self.selenium.quit()
super(StorySixFunctionalTest, self).tearDown()
def test_input_status(self):
selenium = self.selenium
selenium.get('http://127.0.0.1:8000/index/')
status = selenium.find_element_by_id('id_status')
submit = selenium.find_element_by_id('submit')
status.send_keys("Coba Coba")
submit.send_keys(Keys.RETURN)
Update :
I'm trying to debug my program by showing the log of chromedriver, and i got this error instead (which is weird because i have canbera module installed)
Gtk-Message: 14:40:58.177: Failed to load module "canberra-gtk-module"
Gtk-Message: 14:40:58.196: Failed to load module "canberra-gtk-module"

Chrome Driver Options to Open Default Browser and not a new Window Python

I am Trying to Open the chrome in a configuration where all the extensions as well as in logged-in state.
I came across an answer to remove default from the chrome driver Options Module. However, when I added this and tried to execute the program runs Opens a new window with everything enabled, but it does not proceed to open the URL specified and stays at starting page.
Here is my code:
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
options=Options()
options.add_argument("user-data-dir=C:\\Users\\aman krishna\\AppData\\Local\\Google\\Chrome\\User Data\\")
driver=webdriver.Chrome("C:\\Users\\aman krishna\Desktop\\New folder (3)\chromedriver.exe",chrome_options=options)
driver.get("https://www.google.com")
In this code a new window opens but does not search for www.google.com
After some time an error message is displayed i.e
Traceback (most recent call last):
File "C:/Users/aman krishna/PycharmProjects/untitled9/beautifoulsoup.py", line 5, in <module>
driver=webdriver.Chrome("C:\\Users\\aman krishna\Desktop\\New folder (3)\chromedriver.exe",chrome_options=options)
File "C:\Users\aman krishna\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "C:\Users\aman krishna\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Users\aman krishna\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\aman krishna\AppData\Roaming\Python\Python36\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\aman krishna\AppData\Roaming\Python\Python36\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: Chrome failed to start: crashed
(Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 6.3.9600 x86_64)

Categories