Specifying optional arguments when initializing chrome webdriver causes status code 1 - python

Using selenium to test some features of a website and I can't figure out why specifying optional arguments causes it to fail.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver = webdriver.Chrome(
executable_path=driver_dir,
service=Service(driver_dir, log_path=self.crawl_dir)
)
I have also tried:
driver = webdriver.Chrome(
executable_path=driver_dir,
service_log_path=log_dir
)
Both of these examples cause the following output:
Traceback (most recent call last):
...
...
...
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 89, in __init__
self.service.start()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 110, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Users\user\Desktop\Programs\JQuery_Testing\Crabby_Crawler\lib\..\driver\chromedriver.exe unexpectedly exited. Status code was: 1
When I don't specify any optional arguments it works fine:
driver = webdriver.Chrome(
executable_path=driver_dir
)
Any help is greatly appreciated!

Related

Why isn't my chrome profile responding to driver commands?

from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("user-data-dir=C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 4")
driver = webdriver.Chrome
('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
Successfully opens my profile, it won't search for this website nor click any xpaths.
My chrome driver is located at C:\\webdrivers\\chromedriver.exe but when I use that instead of C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe it won't open my profile, just a non signed-in version of chrome :(
If I use
C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe
instead it returns this error:
Traceback (most recent call last):
File "C:\Users\oacoo\OneDrive\Desktop\bots\bot\xoldver\likesmodule\password reset\passcode.py", line 18, in <module>
driver = webdriver.Chrome('C:\\Users\\oacoo\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe', options=options)
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\oacoo\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 109, in assert_process_still_running
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Service C:\Users\oacoo\AppData\Local\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
help me load a page using my chrome profile please!

I can't open a website using selenium with chrome profile

okay so here is my code:
import schedule
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=C:/Users/soham/AppData/Local/Google/Chrome/User Data")
options.add_argument('--profile-directory=Profile 2')
driver = webdriver.Chrome( executable_path="C:\Program Files (x86)\chromedriver.exe", options=options)
driver.get("google.com")
it gives this error:
C:\Users\soham\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/soham/PycharmProjects/pythonProject/main.py
Traceback (most recent call last):
File "C:\Users\soham\PycharmProjects\pythonProject\main.py", line 12, in <module>
driver = webdriver.Chrome( executable_path="C:\Program Files (x86)\chromedriver.exe", options=options)
File "C:\Users\soham\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\soham\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\soham\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\soham\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\soham\PycharmProjects\pythonProject\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
okay so sorry if you're reading this cause i'm only writing this part cause it was saying its most code and told me to write something soo yeah....HELP.

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"

Selenium driver.get() throws Exception

When i'm running this code:
from selenium import webdriver
import time
driver = webdriver.Chrome('C:/Program Files
(x86)/Google/Chrome/Application/chrome.exe')
driver.get('https://www.google.com/')
It only opens my browser but not the URL that was passed as a parameter to driver.get().
Given below is the traceback:
Traceback (most recent call last):
File "C:\Users\efiqq\OneDrive\Plocha\Python\Link.py", line 4, in <module>
driver = webdriver.Chrome('C:/Program Files (x86)/Google/Chrome/Application/chrome.exe')
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\efiqq\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:/Program Files (x86)/Google/Chrome/Application/chrome.exe unexpectedly exited. Status code was: 0
The path you have to pass is not to chrome.exe. You have to point to the chromedriver.exe;
You can get it here: http://chromedriver.chromium.org/downloads

Unable to console logs from safari using selenium webdriver python

I am trying to get console logs of safari using selenium webdriver.
from selenium import webdriver
import time
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
d = DesiredCapabilities.SAFARI
d['logginfPrefs']={'browser':'ALL'}
driver = webdriver.Safari(desired_capabilities=d)
driver.get("test.com")
time.sleep(10)
driver.find_element_by_xpath("//input[#placeholder='Your Name (Required)']").send_keys("test")
for entry in driver.get_log('browser'):
print entry
time.sleep(10)
But getting following error
Traceback (most recent call last):
File "/Users/Fuzebox_6/PycharmProjects/Codechef/test.py", line 14, in <module>
for entry in driver.get_log('browser'):
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 1053, in get_log
return self.execute(Command.GET_LOG, {'type': log_type})['value']
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: The command 'POST /session/3A5DB2BA-CE01-4D7C-895E-32F1C3381F7A/log' is not implemented.
Can some one please tell me what are the flags needed to get console logs

Categories