find_element_by_name() method would fit here:
driver.find_element_by_name("quantity")
Answer from alecxe on Stack OverflowPython Selenium Find Element by Name - Stack Overflow
Selenium Python 2 find element by name and value? - Stack Overflow
Finding Element by Name Attribute in Selenium Python - LambdaTest Community
Finding elements by class name with Selenium in Python - Stack Overflow
Videos
find_element_by_name() method would fit here:
driver.find_element_by_name("quantity")
In September 2022 with Selenium 4.4.0 the correct answer would be:
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Firefox()
inputElement = driver.find_element(by=By.NAME, value='quantity')
Try this
//input[@name='action' and @value=' Search ']
Answering your questions,
1 - Yes you can,
driver.find_element_by_name(‘foo’)
http://selenium-python.readthedocs.org/en/latest/api.html#selenium.webdriver.remote.webdriver.WebDriver.find_element_by_name
2 - I always try to avoid xpath because sometimes it doesn't work properly. Instead, you should always try to find by name or id .. I think is the best case.
You can try to get the list of all elements with class = "content" by using find_elements_by_class_name:
a = driver.find_elements_by_class_name("content")
Then you can click on the link that you are looking for.
By.CLASS_NAME was not yet mentioned:
from selenium.webdriver.common.by import By
driver.find_element(By.CLASS_NAME, "content")
This is the list of attributes which can be used as locators in By:
CLASS_NAME
CSS_SELECTOR
ID
LINK_TEXT
NAME
PARTIAL_LINK_TEXT
TAG_NAME
XPATH