Can't send keys selenium webdriver python

后端 未结 4 773
庸人自扰
庸人自扰 2021-01-21 08:16

Trying to execute simple test

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()

driver.get(\'http://g         


        
4条回答
  •  佛祖请我去吃肉
    2021-01-21 08:40

    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()
    

提交回复
热议问题