Q:

Getting value of a class in selenium and python

<input id="value(Medications1)_139038" class="medMedications text-field" type="text" style="width:90%" value="Lantus" maxlength="30000" name="value(Medications1)" autocomplete="off"/>

So there is this page where there are textboxes and these textboxes are not fixed in number. other times it could be 20 and sometimes just 5 it's random. So is there a way to know how many of these textboxes are in the page? and get the values of those textboxes?
I've tried this:
medicationstextbox_locator = "//*[@class='medMedications text-field ']"
medicationstextbox_locatorTextBox = driver.find_elements_by_xpath(medicationstextbox_locator)

for i in medicationstextbox_locatorTextBox:
    print(i.get_attribute("values"))

this prints out a lot of None.
I don't get it caused I've accessed it's class, pulled the value but it returns None.
If it's possible I'd want to avoid doing:
medications1 = "//input[@name='value(Medications1)']"
medications2 = "//input[@name='value(Medications2)']"

med1textbox = driver.find_element_by_xpath(med1)
med2textbox = driver.find_element_by_xpath(med2)

med1textbox.get_attribute("value")
med2textbox.get_attribute("value")

because I'd have to define each textbox and the number of textboxes is not known beforehand. It would also take so much time to do it this way. So, how do we solve this?

A:

print(i.get_attribute("values"))

There is no values attribute, hence, you are getting Nones. There is value attribute.
Aside from that, your first approach totally makes sense and should work.
We can make it a bit simpler and use a "CSS selector" via find_elements_by_css_selector():
medications = driver.find_elements_by_css_selector("input.medMedications")

# count
print len(medications)

# values
for medication in medications:
    print medication.get_attribute("value")

Alternatively, you can check whether an id attribute contains Medications:
medications = driver.find_elements_by_css_selector("input[id*=Medications]")

or, in case of XPath:
medications = driver.find_elements_by_xpath("//input[contains(@id, 'Medications']")

