0

I am using Selenium to clear old text in a text area before input new text in a web browser. This is my code:

MY_UDP_SESSION = 32768
elem = driver.find_element_by_id("udp-session-quota").clear()
time.sleep(1)
elem.send_keys(MY_UDP_SESSION)

but I see this error:

'NoneType' object has no attribute 'send_keys'

1

1 Answer 1

0

clear()

clear() clears the text if it's a text entry element and is defined as:

def clear(self):
    """Clears the text if it's a text entry element."""
    self._execute(Command.CLEAR_ELEMENT)

As clear() doesn't returns anything hence as per your line of code:

elem = driver.find_element_by_id("udp-session-quota").clear()

elem is assigned as null i.e. NoneType. Moving forward when you try to invoke send_keys() on elem:

elem.send_keys(MY_UDP_SESSION)

You see the error.


Solution

Once the WebElement is returned then you can invoke clear() and send_keys() as follows:

MY_UDP_SESSION = "32768"
elem = driver.find_element_by_id("udp-session-quota")
elem.clear()
elem.send_keys(MY_UDP_SESSION)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.