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!
Related
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.
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?
Here is my Splinter code -
b = Browser()
b.visit("http://boingboing.net")
b.fill("q", "OpenXC")
At this point, I would like to press "Enter" for the search to happen.
This is very similar to the example in the Splinter tutorial page. In this instance, there is really no button element present.
I see that this Search box is a Google Search Box with an id "cse-search-box". I do not know how to trigger search here.
Can you please help?
Metaphy's (thanks, btw) code below generates a traceback for me -
Traceback (most recent call last):
File "/Users/muthu/Desktop/boing.py", line 5, in
b.execute_script('document.getElementsByName("f")[0].submit()')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/splinter/driver/webdriver/init.py", line 58, in execute_script
self.driver.execute_script(script)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 397, in execute_script
{'script': script, 'args':converted_args})['value']
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 158, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'waiting for evaluate.js load failed' ; Stacktrace:
at r (file:///var/folders/5r/06jrtyyn2kd8ty05m71lm0hr0000gn/T/tmpBFCIVe/extensions/fxdriver#googlecode.com/components/driver_component.js:8360)
at fxdriver.Timer.prototype.runWhenTrue/g (file:///var/folders/5r/06jrtyyn2kd8ty05m71lm0hr0000gn/T/tmpBFCIVe/extensions/fxdriver#googlecode.com/components/driver_component.js:392)
at fxdriver.Timer.prototype.setTimeout/<.notify (file:///var/folders/5r/06jrtyyn2kd8ty05m71lm0hr0000gn/T/tmpBFCIVe/extensions/fxdriver#googlecode.com/components/driver_component.js:386)
I can not access the http://boingboing.net site, so I take baidu.com for example:
from splinter.browser import Browser
b = Browser('firefox')
b.visit('http://www.baidu.com')
b.fill('wd', 'test')
b.execute_script('document.getElementsByName("f")[0].submit()')
New answer:
browser.fill('some_name', 'some_value\r')
I have a textfield on a web page that I want to feed data with but the problem is my python-selenium script is not able to locate it when it runs and reaches that page. The weird part is when i try to locate this textfield manually, I am able to do so without any problem. I am using CSSSelector to locate this field.
Stack trace:
Traceback (most recent call last):
File "C:/SWInstallation/TestCases/TestCases\Program.py", line 23, in test_UC_QS_FR_01_1_QuikShip_Support
bhp.enterAccDetails("0004341080", "00200")
File "C:\SWInstallation\HC-Branch\src\HomePage.py", line 24, in enterAccDetails
accInputField = self.driver.find_element_by_css_selector("#fields input[name='ACCOUNT_NUMBER']")
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 366, in find_element_by_css_selector
return self.find_element(by=By.CSS_SELECTOR, value=css_selector)
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 680, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\selenium\webdriver\remote\errorhandler.py", line 158, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u"Unable to find element with css selector == #fields input[name='ACCOUNT_NUMBER']"
Have you tried something like this:
e = self.driver.find_element_by_id("fields")
inputs = e.find_elements_by_css_selector("input[name='ACCOUNT_NUMBER']")