I am using Python Selenium and am trying to select in input box that does not have an ID
<div class="form-group"><input type="email" class="form-control" name="quantity" placeholder="Type a quantity"></div>
inputElement = driver.find_element_by_id("quantity")
What is the best way to select this element, by name?
By.name Selenium locator is used to identify the elements of a webpage. This attribute can be mentioned as part of multiple tags like < input >, < button >, < select > etc. Unlike ID, this may or may not be unique to a page. A webpage may contain multiple tags with the same By.name attribute value.
Selenium WebDriver's By class provides a tagName() method to find elements by their HTML tag name. This is similar to the getElementsByTagName() DOM method in JavaScript. This is used when you want to locate elements using their tag name, for example, locating all <tr> tags in a table.
Python – find_element() method in Selenium In order to find element by “id” find_element() method is used. Id is basically unique attribute assigned to the elements of the web page such as buttons, image, heading etc. Note: The first element with the “id” attribute value matching the location will be returned.
find_element_by_name()
method would fit here:
driver.find_element_by_name("quantity")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With