Selenium Error: Unable to find a matching set of capabilities [duplicate] - python

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.

Related

Internet Explorer NOT working in headless mode with Selenium [Using headless_ie_selenium]

I am aware that IE does not support headless. But there's a workaround of using virtual desktops on Windows to get it done. This is what https://github.com/kybu/headless-selenium-for-win is doing, but I seem to be running into an issue here.
My IEDriverServer.exe is added to $PATH$, and headless_ie_selenium.exe is also in the same directory as the IEDriverServer.exe
I'm trying to use it like this:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Ie('C:\IEDriverServer_Win32_3.150.1\headless_ie_selenium.exe')
browser.get('www.someurl.com')
I'm pasting the traceback below
Traceback (most recent call last):
File "C:\Users\hjind\Desktop\pythonRCM\headless_ie.py", line 16, in <module>
browser = webdriver.Ie('C:\IEDriverServer_Win32_3.150.1\headless_ie_selenium.exe')
File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\ie\webdriver.py", line 93, in __init__
RemoteWebDriver.__init__(
File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\hjind\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium-3.141.0-py3.9.egg\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unexpected error launching Internet Explorer. IELaunchURL() returned HRESULT 80070012 ('There are no more files.') for URL 'http://localhost:57762/'
The only thing that worked for me was to programatically minimise the IE window on launch, and switch to another virtual desktop while the job runs.
Setting introduce_flakiness_by_ignoring_security_domains helped bypass the "Protected Mode" and "Zoom Level" errors.

Whenever I try to run Chrome using selenium using Python I get this error. has anyone experienced this before?

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.

Open chrome with specific user profile using selenium on python mac [duplicate]

This question already has answers here:
How to open a Chrome Profile through Python
(2 answers)
How to open a Chrome Profile through --user-data-dir argument of Selenium
(3 answers)
How to use existing login token for telegram web using selenium webdriver
(2 answers)
Closed 2 years ago.
I'm trying use Selenium to open chrome using a specific profile. I located the profile location in chrome://version and used the following code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument(
"user-data-dir=../../Library/Application Support/Google/Chrome/Profile 2/")
driver = webdriver.Chrome(
executable_path='./chromedriver', options=options)
driver.get("https://google.com")
But instead, it throws this error:
Traceback (most recent call last):
File "select_files.py", line 10, in <module>
driver = webdriver.Chrome(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/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: cannot parse internal JSON template: Line: 1, column: 1, Unexpected token.
I tried using without the /profile 2/ but it still comes up with this error
I am using Python 3, Selenium 1.25.9, Chrome Version 85.0.4183.83, Chrome Driver MacOS Catalina

Issue with browser = Browser('firefox') part of my code

I am running updated versions of my all modules within my python. I am using conda-forge and spyder 3.7.
I am just attempting to open a webpage using some basic code and I get stuck there.
I have searcher just about everywhere on the site, but I am not sure what I should do since I am quite new to this.
I have updated the modules I am using and continued after every update but it was to no avail.
Here is my code:
from splinter import Browser
browser = Browser('firefox')
browser.visit('https://google.com')
Previously written as:
from splinter import Browser
browser = Browser()
browser.visit('https://google.com')
Same issue with both.
Here is the error:
Traceback (most recent call last):
File "<ipython-input-12-71643798329a>", line 2, in <module>
browser = Browser('firefox')
File "build/bdist.macosx-10.5-x86_64/egg/splinter/browser.py", line 53, in Browser
return driver(*args, **kwargs)
File "build/bdist.macosx-10.5-x86_64/egg/splinter/driver/webdriver/firefox.py", line 33, in __init__
self.driver = Firefox(firefox_profile)
File "C:\Users\lkerzabi\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in __init__
keep_alive=True)
File "C:\Users\lkerzabi\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\lkerzabi\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\lkerzabi\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\lkerzabi\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
SessionNotCreatedException: Unable to find a matching set of capabilities
I expect to be able to open a webpage, but it just gives me this error.
Have you checked this issue from Github Selenium 3.4.0 Unable to find matching capabilities ?
Particularly those two answers:
First option
Second option
Seems like you are experiencing the same issue

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