Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Get input values using Selenium in Python outputs None

My Item:

<input id="a0" class="someclassname" size="55" placeholder="empty" value="scarping-test">

My Code:

items = driver.find_elements(By.XPATH,"//input[@id='a0']")
for item in items:
    href = item.get_attribute('href')
    print(href)

Output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

None

Expected:

scarping-test

>Solution :

That input doesn’t have an href attribute. The attribute you’re looking for is called value.

So what you are looking for is:

item = driver.find_element(By.XPATH, "//input[@id='a0']").get_attribute('value')

I used find_element() instead of find_elements() since it has no sense to find for more than one element and loop through the list; the element with id='a0' can only be one (id is a unique identifier).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading