Trying to execute simple test
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get(\'http://g
You must change the reference element
driver.get('http://google.com')
elem.find_element_by_name('q')
elem.send_keys('hey')
Its with the version of selenium which is causing the issue. I faced the same issue.
Its with the selenium version 3.3.3 which has the compatibility problem.
Try: pip uninstall selenium pip install selenium==3.3.1
Hope it works.
WebDriver instance does not have send_keys()
method. That's what the error is actually about:
'WebDriver' object has no attribute 'send_keys'
Call send_keys()
on a WebElement instance which is returned by find_element_by_*()
methods - find_element_by_name()
in your case:
element = driver.find_element_by_name('q')
element.send_keys("hey")
And just FYI, there is also an ActionChains class which is useful do build up chains of actions or apply more complex actions like drag&drop or mouse move. It's an overhead in this case, but just for the sake of an example:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element(element).send_keys("hey").perform()
Did you try changing your reference element. It would be a good practice if you call webdriver using different reference. Your code after changing reference.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
driver.get('http://google.com')
#Firefox Webdriver is created and navigated to google.
elem = driver.find_element_by_name('q')
elem.send_keys('hey',Keys.RETURN)
#Keys.RETURN = Pressing Enter key on keyboard
time.sleep(5)
driver.close()