Finding Element by Name Attribute in Selenium Python

How to find an element by its name attribute using Selenium in Python? Below is my HTML file and code where i am trying to get the attribute name

<div class="form-group">
    <input type="email"
           class="form-control"
           name="quantity"
           placeholder="Type a quantity">
</div>```

inputElement = driver.find_element_by_id("quantity")

Hii, to find an element by its name attribute using Selenium in Python, you can use the find_element_by_name method. Here are three different ways to achieve this:


# Using find_element_by_name method:

inputElement = driver.find_element_by_name("quantity")

This method directly finds the element using its name attribute. It’s the most straightforward and recommended way to locate elements by name.

Speaking of simplicity, you can also utilize a CSS selector to locate the element. This becomes handy when dealing with more complex selectors or when the element has additional attributes for identification:


# Using CSS selector:

inputElement = driver.find_element_by_css_selector("input[name='quantity']")