radishapplepie
radishapplepie

Reputation: 23

send_keys() giving error in python 3 selenium code with firefox

My code is:

from selenium import webdriver

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException

baseurl = "https://www.google.ca/?gfe_rd=cr&ei=J5ooWerXOsf_8AebtKKICw&gws_rd=ssl"
search = "panda"

xpaths = { 'searchbox' : ".//*[@id='lst-ib']",
   'submit' : ".//*[@id='tsf']/div[2]/div[3]/center/input[1]",
   'img' : ".//*[@id='gbw']/div/div/div[1]/div[2]/a"
 }

driver = webdriver.Firefox()
driver.get(baseurl)

driver.find_element_by_xpath(xpaths['searchbox']).clear()
driver.find_element_by_xpath(xpaths['searchbox']).send_keys(search)
driver.find_element_by_xpath(xpaths['submit']).click()
#driver.find_element_by_xpath(xpaths['img']).click()

Firefox opens, but nothing at all happens, and written in the terminal is the following:

Traceback (most recent call last):
File "sg1.py", line 21, in <module>
driver.find_element_by_xpath(xpaths['searchbox']).send_keys(search)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webelement.py", line 347, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webelement.py", line 494, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected [object Undefined] undefined to be a string

Things to note: Firefox is up to date.

When Firefox opens it opens a plain version and not the version that usually opens with add-ons such as adblocker, firebug, etc.

When i ran just the click on 'img' bit that is commented out it did what it was supposed too.

Upvotes: 1

Views: 449

Answers (1)

Kushal Bhalaik
Kushal Bhalaik

Reputation: 3384

This issue is common with geckodriver v.015; In order to resolve this update your geckodriver version to 0.16 also selenium to 3.4.0.

Upvotes: 1

Related Questions