Heroku/flask/selenium—can't find file in traceback / weird valueError - python

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.

Related

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

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.

selenium.common.exceptions.WebDriverException: Message: Error loading page for the Firefox SSL

from selenium import webdriver
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities['acceptSslCerts'] = False
driver = webdriver.Firefox(capabilities=capabilities)
driver.get('https://cacert.org/')
driver.quit()
I tried the above script to handle the SSL, but I get the error:
C:\Python27\python.exe "C:/Users/alokv/AppData/Roaming/JetBrains/PyCharm Community Edition 2016.3.2/jre/jre/bin/NIOS_UI_Automation/test_log.py"
Traceback (most recent call last):
File "C:/Users/alokv/AppData/Roaming/JetBrains/PyCharm Community Edition 2016.3.2/jre/jre/bin/NIOS_UI_Automation/test_log.py", line 13, in <module>
driver.get('https://cacert.org/')
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 248, in get
self.execute(Command.GET, {'url': url})
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Error loading page
Can anyone please help me by explaining why this happens?
I ran your code and it worked fine. I am almost certain that your problem is the website never loads probably due to slow internet. You can insert an assert "CAcert.org" in driver.title to make sure that the page is loaded before you continue to whatever is next.

Python + Selenium to submit query on webpage

Hello all…I am trying to use Python and Selenium to submit query, a pair of coordinates “40.67243, -74.08379” on Google Map.
driver = webdriver.PhantomJS()
driver.get('https://maps.google.com/')
driver.find_element_by_id("searchboxinput").clear()
driver.find_element_by_id("searchboxinput").send_keys("40.67243, -74.08379")
driver.find_element_by_css_selector("button.searchbutton").click()
using above returns chunk of error message and problem starts from:
driver.find_element_by_id("searchboxinput").clear()
when I check it from Chrome, and seems there’s no an element “searchboxinput”. Is it the reason?
What’s the way to submit query? Thanks.
the error:
Traceback (most recent call last):
File "C:\Python27\Gmap.py", line 10, in <module>
driver.find_element_by_id("searchboxinput").clear()
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 197, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 681, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 164, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\selenium\webdriver\remote\errorhandler.py", line 164, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'{"errorMessage":"Unable to find element with id \'searchboxinput\'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"95","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:62738","User-Agent":"Python-urllib/2.7"},"httpVersion":"1.1","method":"POST","post":"{\\"using\\": \\"id\\", \\"sessionId\\": \\"e6a0af20-4f91-11e4-a8b7-7b4551650c5b\\", \\"value\\": \\"searchboxinput\\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/e6a0af20-4f91-11e4-a8b7-7b4551650c5b/element"}}' ; Screenshot: available via screen
Everithing seems fine. Exception says that there is no element with id searchboxinput. So maybe you confused id with class or something like that?

Unable to login to Quora using Selenium webdriver in Python

I am using a Selenium module in Python to log into Quora. It works fine for Facebook, but I am getting an error on the send_keys('my_email') line while trying it on Quora:
I am using the following script.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
driver.get('http://www.quora.com/')
time.sleep(60)
username = driver.find_element_by_name('email')
time.sleep(60)
username.send_keys('my_email')
time.sleep(60)
password = driver.find_element_by_name('password')
time.sleep(60)
password.send_keys('my_password')
time.sleep(60)
password.send_keys(Keys.RETURN)
driver.close
Sleep time is not a problem here, because I tried executing a script line by line using the Python shell.
Error:
Traceback (most recent call last): File "", line 1, in
password.send_keys('my_password') File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 293, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing}) File
"C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 370, in _execute
return self._parent.execute(command, params) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 173, in execute
self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 164, in check_response
raise exception_class(message, screen, stacktrace) ElementNotVisibleException: Message: u'Element is not currently
visible and so may not be interacted with' ; Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:8791:5)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11438:1)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11455:11)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11460:7)
at DelayedCommand.prototype.execute/< (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11402:5)
The problem is that there are multiple inputs with name="email".
You need the one in the "Regular Login" section:
form = driver.find_element_by_class_name('regular_login')
username = form.find_element_by_name('email')
username.send_keys('my_email')
password = form.find_element_by_name('password')
password.send_keys('my_password')

Selenium click() from link text throwing exception on Windows

Using python from command line, I execute the following:
driver = webdriver.Firefox()
driver.get('http://amazon.com/mp3')
el = driver.find_element_by_link_text('MP3 Downloads : MP3 Songs')
el.click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium-2.19.1-py2.7.egg\selenium\webdriver\remote\webelement.py", line 45, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium-2.19.1-py2.7.egg\selenium\webdriver\remote\webelement.py", line 194, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium-2.19.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 153, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.19.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 147, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'current is undefined'
I have no idea what "CURRENT" is...
I ran it on a different machine and the error became
...Message u'l is undefined'
Any suggestions? By the way this only happens for Windows on Firefox.
I've had the same issue when clicking a button.
You can click it by sending the "space" character:
webDriver.FindElement("button_id").SendKeys(" ");
Hope it helps!

Categories