selenium 'nonetype' object has no attribute 'send_keys'

13,281

You've assigned method call (clear()) which returns None to title variable while you need to define WebElement and call methods subsequently as

title = driver.find_element_by_id("subject")
title.clear()
title.send_keys("title")
Share:
13,281

Related videos on Youtube

achille
Author by

achille

Updated on June 04, 2022

Comments

  • achille
    achille almost 2 years
    title='this is the title'
    

    I want to locate with python/selenium, within a web page, this line:

    <input id="subject" name="subject" maxlength="50" value="" class="nude error" type="text">
    

    I use this code with python-selenium (under Debian):

    title = driver.find_element_by_id("subject").clear()
    title.send_keys(title) 
    

    I got the following error:

    Traceback (most recent call last):
    
      File "./basic0", line 49, in <module>
    titre.send_keys(title)
    
    AttributeError: 'NoneType' object has no attribute 'send_keys'
    

    note:when the script stops because of this error, the mouse cursor is at the right at place within the web page; but I cannot find a way to send_keys to fill in the input

    I also tried:

    title = driver.find_element_by_xpath("div[contains(text(),'subject')]")
    
    title = driver.find_element_by_xpath("//form[input/@id='subject']")
    
    title = driver.find_element_by_xpath("//form[input[@name='subject']")
    

    but it does not work; furthermore the mouse cursor is not at the right place.

    then I tried a later selenium version:

    I completly purge python-selenium package under Debian (which is selenium v. 2.53) then

    pip install selenium==3.3.1
    

    This time, when I launch the script it says that geckodriver is missing: so,

    wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux32.tar.gz
    
    tar -xvzf geckodriver-v0.23.0-linux32.tar.gz
    
    chmod 755 geckodriver (I also tried 777)
    
    mv geckodriver /usr/local/bin/ (so it's in my PATH)
    

    now when I launch the script, here is the error message I got:

    Traceback (most recent call last):
    
      File "./basic0", line 13, in <module>
    driver = webdriver.Firefox()
    
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
    keep_alive=True)
    
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
    
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
    
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
    self.error_handler.check_response(response)
    
      File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
    raise exception_class(message, screen, stacktrace)
    
    selenium.common.exceptions.WebDriverException: Message: connection refuse
    

    firefox window pops-up, and then shutdown when the script stops

  • achille
    achille over 5 years
    I tried your solution and first got: "AttributeError: 'WebDriver' object has no attribute 'clear' ". I then removed title.clear(); it worked but filled the input in with 'title' instead of the variable content. I then tried driver.send_keys(title): it was ok. Now just wondering why clear() did not work. Thank you indeed!
  • Andersson
    Andersson over 5 years
    @achille , I guess you tried driver.clear() instead of title.clear() (title should be object of type WebElement)