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.
Related
I want to use 2 experimental options on my selenium chromedriver project, but I don't get enough information about the "add_experimental_option" function, I want to use 2 experimental options "prefs" and "debuggerAddress", and when I try to run it, it gets error, I can only use one of them, how can I use both of them?
opt = Options()
opt.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
opt.add_experimental_option("prefs", { \
"profile.managed_default_content_settings.images": 2
})
error messages
Traceback (most recent call last):
File "exampleselenium.py", line 28, in <module>
driver = webdriver.Chrome(executable_path="chromedriver.exe",options=opt,service_log_path='NUL')
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Faraaz\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Faraaz\anaconda3\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: cannot parse capability: goog:chromeOptions
from invalid argument: unrecognized chrome option: prefs
ChromeOptions objects
prefs [type: dictionary]: A dictionary with each entry consisting of the name of the preference and its value. These preferences are only applied to the user profile in use.
debuggerAddress [type: string]: An address of a Chrome debugger server to connect to, in the form of <hostname/ip:port>, e.g. '127.0.0.1:38947'
You can add both the experimental_option as follows:
opt = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images" : 2}
opt.add_experimental_option("prefs", prefs)
opt.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=opt, service_log_path='NUL')
Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path = r"C:\Users\Dell\Desktop\chromedriver.exe")
driver.get("http:/https://stackoverflow.com/")
Traceback (most recent call last):
File "C:\Users\Dell\Desktop\Intro.py", line 3, in
driver = webdriver.Chrome(executable_path = r"C:\Users\Dell\Desktop\chromedriver.exe")
File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in init
RemoteWebDriver.init(
File "C:\Users\Dell\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\Dell\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\Dell\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\Dell\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.WebDriverException: Message: unknown error: failed to write prefs file
This can cause if your C drive has not enough space. So use any tools like Disk Cleaner or CCleaner to free up some space.
Here is my version of the working code.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path="C:\Windows\chromedriver.exe")
driver.get("https://stackoverflow.com/")
Try adding chromedriver to C:\Windows.
Check both chrome and chromedriver having the same version.
This question already has an answer here:
Selenium “Unable to find a matching set of capabilities” despite driver being in /usr/local/bin
(1 answer)
Closed 2 years ago.
This is the code I am using
from selenium import webdriver
url = "https://www.reddit.com/r/memes"
browser = webdriver.Firefox()
browser.get(url)
This is the error
Traceback (most recent call last):
File "main.py", line 4, in <module>
browser = webdriver.Firefox()
File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
I am using WSL with Ubuntu and I am using Vim. I do not get this error however if I am outside of WSL and use VSC instead. But I want to code in Vim.
In the code, you haven't mentioned the path to the geckodriver executable. Your code should look something like this:
from selenium import webdriver
url = "https://www.reddit.com/r/memes"
browser = webdriver.Firefox(f'/home/user/Downloads/geckodriver')
# Or in Windows the path would be 'C:\\Users\\username\\Downloads\\geckodriver.exe'
browser.get(url)
If you don't already have the driver, get it from here.
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)
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