1

I want to pull the length of an input that is entered into a website's text box to see the max amount of characters that it will allow. The HTML says that the max length is 40 so I am trying to enter 41 characters to see if it will only take the first 40 characters entered. When I run the code that I have, I get AttributeError: 'NoneType' object has no attribute 'get_attribute'

This is my code so far:

def test_FN_SPmax(self):
    time.sleep(3)
    first_name = self.driver.find_element_by_xpath(
        '/html/body/div[4]/div[1]/section/div[2]/div[1]/div[4]/div/div/div/div/div/div[2]/div/div[1]/section/div/section/div/div/div/div/div/div[1]/div/div/div/fieldset/div/div[2]/input').send_keys(
        ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(41)))
    time.sleep(2)
    typedValue = first_name.get_attribute('value')
    size = typedValue.length()
    print(size)

1 Answer 1

1
first_name 

is not a web element anymore cause you did use .send_keys

so do this instead :

first_name = self.driver.find_element_by_xpath('/html/body/div[4]/div[1]/section/div[2]/div[1]/div[4]/div/div/div/div/div/div[2]/div/div[1]/section/div/section/div/div/div/div/div/div[1]/div/div/div/fieldset/div/div[2]/input')
first_name.send_keys('something here')
time.sleep(2)
typedValue = first_name.get_attribute('value')

Should work for you.

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.