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
Related
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.
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'm using Selenium (with python) to monitor a page periodically and save screenshots. This is done on a raspberry pi (armv6). Because of this, I'm using PhantomJS.
I'm monitoring certain elements, and since a raspberry pi isn't the fastest, I am executing a script with driver.execute_script to make the page smaller so that the screenshots aren't too big.
Unfortunately, when executing this script, the following error is thrown:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "`**path**`/bot.py", line 39, in __init__
self.graphs(self.threads['graphs'])
File "`**path**`/bot.py", line 93, in graphs
self.driver.execute_script(`**script**`)
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 543, in execute_script
'args': converted_args})['value']
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 308, in execute
self.error_handler.check_response(response)
File "/usr/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: {"errorMessage":"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' *.google-analytics.com\".\n","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"716","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:46451","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"POST","post":"{\"script\": `**script**`, \"args\": [], \"sessionId\": \"69182660-cd69-11e7-b52d-9131a53fa749\"}","url":"/execute","urlParsed":{"anchor":"","query":"","file":"execute","directory":"/","path":"/execute","relative":"/execute","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/execute","queryKey":{},"chunks":["execute"]},"urlOriginal":"/session/69182660-cd69-11e7-b52d-9131a53fa749/execute"}}
Screenshot: available via screen
I've googled this error but I haven't been able to find a solution. Is this Selenium that's preventing me from executing this script or is a PhantomJS?
Thanks!
[edit]
Here's the code that's initializing the selenium webdriver:
def __init__(self):
self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any', '--web-security=false'])
self.driver.set_window_size(1070, 800)
self.threads = {'check_login': threading.Event(), 'graphs': threading.Event()}
self.login()
self.graphs(self.threads['graphs'])
self.check_login(self.threads['check_login'])
Background: Flask app on Heroku. Python 3.4 in venv. I'm using the Selenium webdriver (2.53.2) Here's the traceback:
The desired behavior is for it to send the keys to the value of the web element.
The specific problem or error:
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#onyen"))
).send_keys(onyen)
The traceback is
Traceback (most recent call last):
File "driver.py", line 332, in <module>
to_shopping_cart(phantom=True)
File "driver.py", line 47, in to_shopping_cart
).send_keys(onyen)
File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 322, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webelement.py", line 457, in _execute
return self._parent.execute(command, params)
File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/app/.heroku/python/lib/python3.4/site-packages/selenium/webdriver/remote/errorhandler.py", line 165, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: TypeError - undefined is not a function (evaluating '_getTagName(currWindow).toLowerCase()')
I have no idea how to fix this traceback, after opening all the files listed.
Here is the shortest code necessary to reproduce the question itself, provided you're in a venv of python 3.4 with selenium 2.53.2
from selenium import webdriver
driver = webdriver.PhantomJS() # webdriver.Firefox() works no problem
driver.get("https://sso.unc.edu/idp/Authn/UserPassword")
WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "#onyen"))
).send_keys(onyen)
It is important to note that the same error is thrown on Heroku bash and my own machine, however on my own machine the file paths start with /venv/python3.4 instead of /.heroku/python/lib/python3.4.
Iam tested webscraping the page:http://www.guiadosquadrinhos.com/todas-capas-disponiveis
I need navigate in pagination geting info pages favorite.
I need click link javascript next page:
javascript:__doPostBack('ctl00$MainContent$lstProfileView$dataPagerNumeric2$ctl02$ctl00')
from selenium import webdriver
import time
driver = webdriver.PhantomJS(executable_path='C:\Python27\Tools\phantomjs\phantomjs.exe')
driver.get("http://www.guiadosquadrinhos.com/todas-capas-disponiveis")
#print(driver.find_elements_by_class_name("numero_capinha")[0].text)
#driver.find_elements_by_class_name("next_last")[0].click()
#time.sleep(5)
print(driver.find_elements_by_class_name("numero_capinha")[0].text)
driver.find_elements_by_class_name("next_last")[0].click()
print(driver.find_elements_by_class_name("numero_capinha")[0].text)
My code return:
sobreontem - Independente
Traceback (most recent call last): File "teste_selenium.py", line 10, in
driver.find_elements_by_class_name("next_last")[0].click() File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 74, in click
self._execute(Command.CLICK_ELEMENT) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 453, in _execute
return self._parent.execute(command, params) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 201, in execute
self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 181, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotVisibleException: Message:
{"errorMessage":"Element is not currently visible and may not be
manipulated","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"81","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:63160","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\"sessionId\":
\"5d3cfdc0-5d3b-11e5-b784-67706273a0bb\", \"id\":
\":wdc:1442494581220\"}","url":"/click","urlParsed":{"anchor":"","query":"","file":"click","directory":"/","path":"/click","relative":"/click","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/click","queryKey":{},"chunks":["click"]},"urlOriginal":"/session/5d3cfdc0-5d3b-11e5-b784-67706273a0bb/element/%3Awdc%3A1442494581220/click"}}
Screenshot: available via screen
Whats is problem ?
Since, you are doing the following -
driver.find_elements_by_class_name("next_last")[0].click()
If you look in the source, there are multiple elements with this class name and the first one is disabled, because that is for the previous button and you are on first page.