PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchUse Selenium’s name locator to find an element by the exact value of its HTML name attribute. In Python, write driver.find_element(By.NAME, "newsletter"); in Java or JavaScript, use driver.findElement(By.name("newsletter")). The value is not the control’s visible label or text.
Find an element by name
In this Python example, replace the page URL and newsletter with the page and attribute value used by your test:
As an Amazon Associate I earn from qualifying purchases.
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://example.com/form")
newsletter = driver.find_element(By.NAME, "newsletter")
By.NAME tells Selenium to match the element’s name attribute. For example, it can locate markup such as <input name="newsletter">. It does not search for the word “newsletter” in the element’s label, visible text, ID, or value.
Free tools Windows power users keep installed
One-click scans. No signup required.
Java
WebElement newsletter = driver.findElement(By.name("newsletter"));
JavaScript
const newsletter = await driver.findElement(By.name('newsletter'));
The Selenium documentation describes eight traditional locator strategies: class name, CSS selector, ID, name, link text, partial link text, tag name, and XPath. A name locator is a direct choice when the page has a useful name attribute.
#1 Best Overall
Handle duplicate name values
A page can contain more than one element with the same name, even though Selenium’s locator guidance says name values should generally be unique. A singular lookup with find_element returns the first match in the search context; it does not guarantee that the match is the control you intended.
Use find_elements when duplicates are possible. It returns the matching elements as a collection, or an empty list if there are no matches:
Rank #2
matches = driver.find_elements(By.NAME, "newsletter")
if not matches:
raise LookupError("No element has name='newsletter'")
for element in matches:
print(element.tag_name, element.get_attribute("type"), element.get_attribute("value"))
If the page has repeated names in separate sections, first locate a meaningful parent and search within it:
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →form = driver.find_element(By.ID, "signup-form")
newsletter = form.find_element(By.NAME, "newsletter")
Use a parent locator only when that parent is itself a reliable way to identify the intended section.
Rank #3
Choose the locator that best identifies the control
- ID: Selenium generally prefers an ID when it is available, unique, and predictable.
- Name: Use it when the page’s name attribute clearly identifies the control you need.
- CSS selector: Choose CSS when you need to match an attribute together with other conditions, such as a particular element type.
There is no universally best locator. Prefer one that is unique enough for the intended element, stable as the page changes, and clear to someone maintaining the test.
Troubleshoot a name lookup
- No element found: Check the exact spelling and capitalization of the
nameattribute in the page markup. Confirm that your test has navigated to the expected page before locating the element. - The wrong element was returned: Check whether the page has duplicate name values. Use
find_elementsto inspect the matches, or narrow the search to a meaningful parent. - You searched for a label or visible text: A name locator matches the
nameattribute, not the control’s label or displayed text. Inspect the markup and use a locator strategy suited to the attribute or content you actually need. - The markup has no useful name: Use another locator, such as a stable unique ID or an appropriate CSS selector, rather than assuming the visible label is a name attribute.
Or skip the browser setup
If your goal is a clean screenshot rather than locating or interacting with a form control in a Selenium test, ScreenshotNeo can capture a page with one GET request. This is a separate option: it does not replace Selenium’s DOM locators.
Rank #4
ScreenshotNeo API documentation
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for 1,000 free screenshots a month, with no card required.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Frequently Asked Questions
Does Selenium’s name locator match the element’s value?
No. It matches the element’s `name` attribute. The `value` attribute is separate.
Best Value
Can a name locator find a checkbox?
Yes, if the checkbox has the name attribute value you specify. You can inspect its tag, type, and value after locating it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




