You aren't using the same CSS selector in both instances. Change

[name-firstName]

to

[name='firstName']

in the second instance.

Also, your code looks overly complicated. Have you tried something like this?

Answer from JeffC on Stack Overflow
🌐
Reflect
reflect.run › articles › everything-you-need-to-know-about-nosuchelementexception-in-selenium
Everything you need to know about NoSuchElementException in Selenium | Reflect
NoSuchElementException is one of ... be found. A NoSuchElementException occurs when the Selenium locator strategy defined is unable to find the desired HTML element in the web page....
Discussions

NoSuchElementError: Unable to locate element - Selenium webdriver using Javascript - Stack Overflow
So, I know the issue due to countless hours of research. The only issue is that no one is basing their code like the way I do and/or are not clear on where/what to insert in my code. I know you nee... More on stackoverflow.com
🌐 stackoverflow.com
NoSuchElementException: no such element: Unable to locate element
Are sure the locator is correct? If not, fix the locator If the locator is correct, try to put thread.sleep before pressing enter/clicking on the search button More on reddit.com
🌐 r/selenium
8
4
September 5, 2022
I got Unable to locate element error
[13380:6340:0121/202859.228:ER... (node:4620) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='Shadd Anderson']/../button[... More on teamtreehouse.com
🌐 teamtreehouse.com
5
January 21, 2018
NoSuchElementError: no such element: Unable to locate element:
I get the error UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"*[id="email_create"]"} but I'm sure that this selector exists. More on stackoverflow.com
🌐 stackoverflow.com
August 7, 2019
People also ask

How do you fix no such element exception in Selenium?
To address the “no such element” exception in Selenium, it’s crucial to implement robust strategies that enhance test stability. One effective approach is to utilize explicit waits, ensuring that the element you’re interacting with has fully loaded before proceeding. Additionally, consider using XPath or CSS selectors for more reliable element identification. Employ try-catch blocks to gracefully handle NoSuchElementExceptions, allowing you to implement custom actions like waiting for the element or executing alternatives when it’s not found.
🌐
testmuai.com
testmuai.com › testmu ai › blog › how to fix nosuchelementexception in selenium | testmu ai
How to Fix NoSuchElementException in Selenium | TestMu AI (Formerly ...
How to Fix NoSuchElementException in Selenium
To handle NoSuchElementException, we create a Java project using Maven and TestNG, adding Selenium dependencies for automation testing. You can use a cloud Selenium Grid like TestMu AI to run tests reliably across multiple browsers and devices. Setup Project: Create a Maven project, add Selenium and TestNG dependencies in pom.xml, and configure the IDE of your choice. Initialize WebDriver: Create a RemoteWebDriver instance and set browser options using ChromeOptions or SafariOptions as required. Configure Test Environment: Use TestMu AI credentials or environment variables to connect the WebDr
🌐
testmuai.com
testmuai.com › testmu ai › blog › how to fix nosuchelementexception in selenium | testmu ai
How to Fix NoSuchElementException in Selenium | TestMu AI (Formerly ...
Why Does Selenium Throw a NoSuchElementException?
A NoSuchElementException occurs when Selenium fails to locate an element on a webpage. This usually happens if the element is missing, not yet rendered, or the locator used is incorrect. Handling this requires verifying locators and optionally using waits to ensure elements are accessible before interacting with them.
🌐
testmuai.com
testmuai.com › testmu ai › blog › how to fix nosuchelementexception in selenium | testmu ai
How to Fix NoSuchElementException in Selenium | TestMu AI (Formerly ...
🌐
Educative
educative.io › answers › what-is-nosuchelementexception-in-selenium-python
What is `NoSuchElementException` in Selenium-Python?
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="userNam"]"}
🌐
Testmuai
testmuai.com › testmu ai › blog › how to fix nosuchelementexception in selenium | testmu ai
How to Fix NoSuchElementException in Selenium | TestMu AI (Formerly LambdaTest)
Then, we try to click on one such element and observe the results. On executing this, you can observe that the test case fails with NoSuchElementException as the element is not yet available to be clicked as it is not loaded yet, and hence the element is unavailable. Another reason could be that the passed WebElement locator is incorrect, and no element is present with that reference.
Published   February 17, 2026
🌐
testRigor
testrigor.com › home › no such element exception in selenium: how do you handle it?
No Such Element Exception in Selenium: How Do You Handle It? - testRigor AI-Based Automated Testing Tool
October 16, 2024 - NoSuchElementException is thrown by findElement() method in Selenium WebDriver when the desired element cannot be located using the specified locator (such as an ID, name, class, CSS selector, or XPath).
🌐
Quora
quora.com › How-can-I-solve-this-error-on-Java-Eclipse-Selenium-code-no-such-element-Unable-to-locate-element-even-it-was-working-fine-before
How to solve this error on Java Eclipse Selenium code 'no such element: Unable to locate element' even it was working fine before - Quora
Prefer stable locators: avoid auto-generated IDs or brittle XPaths. Use data-* a ... "No such element: Unable to locate element" in Selenium means WebDriver couldn't find the DOM node with the locator you supplied.
Find elsewhere
🌐
Reddit
reddit.com › r/selenium › nosuchelementexception: no such element: unable to locate element
r/selenium on Reddit: NoSuchElementException: no such element: Unable to locate element
September 5, 2022 -

Hi,

I'm very new to selenium and writing my first script which is a Google search. Th script has trouble clicking on the search button after typing in what to search for. I get a 'NoSuchElementException: no such element: Unable to locate element'. I also changed the script so it presses enter rather than clicking on the button and got the same error. Can you help? I have placed links to screenshots of my code and the error.

https://imgur.com/a/TeNy66B

Thanks

🌐
GeeksforGeeks
geeksforgeeks.org › software testing › understanding-no-such-element-exception-in-selenium
Understanding No Such Element Exception in Selenium - GeeksforGeeks
July 23, 2025 - NoSuchElementException in Selenium is occur when WebDriver is unable to the locate an element on web page. This is happen in the different scenarios, typically related to the issues with the element location, timing or incorrect DOM structure ...
🌐
Google Groups
groups.google.com › g › selenium-users › c › OMgZGydnn0I
Xpath Correct but still get no such element: Unable to locate element:
My Xpath is correct & no iFrame and I can locate element in Chrome console but my program still fails. I have used explicit wait also. website http://newtours.demoaut.com/ I am trying to locate login page and send login id. ... PASSED: openURL FAILED: loginToTours **org.openqa.selenium.NoSuchElementException**: **no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name='userName']"}** *** Element info: {Using=xpath, value=//input[@name='userName']}
🌐
Team Treehouse
teamtreehouse.com › community › i-got-unable-to-locate-element-error-2
I got Unable to locate element error (Example) | Treehouse Community
January 21, 2018 - [13380:6340:0121/202859.228:ER... (node:4620) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='Shadd Anderson']/../button[...
🌐
BrowserStack
browserstack.com › home › guide › understanding no such element exception in selenium
Understanding No Such Element Exception in Selenium | BrowserStack
March 21, 2025 - For example, while automating, the locator value was “//a[@class=’abc_123’]”, however while executing the test the class value got changed to “abc_456”. Such changes in the DOM structure leads to No Such Element Exception in Selenium.
🌐
Stack Overflow
stackoverflow.com › questions › 50395570 › nosuchelement-unable-to-locate-element
node.js - NoSuchElement: Unable to locate element - Stack Overflow
var webdriver = require('selenium-webdriver'); var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build(); driver.get("https://www.imsnsit.org/imsnsit/student.htm"); driver.wait(webdriver.until.elementLocated({xpath: '//*[@id="captchaimg"]'})); var img = driver.findElement({xpath: '//*[@id="captchaimg"]'}); var link = img.getAttribute('src'); console.log(link); ... Please add the HTML as the URL says Please use latest version of Chrome browser to access the Application.. and I don't have chrome ... @Prany here is the link to downloaded copy of webpage, i am not uploading the whole html as it might get too big
🌐
Reddit
reddit.com › r/selenium › how do i handle no such element errors in nodejs?
r/selenium on Reddit: How do I handle no such element errors in nodejs?
November 24, 2020 -

I am attempting to write a simple web automation script, but part of it involves attempting to click a nonexistent button until it appears.

I was able to do this in python with this code:

while True:
try:
driver.find_element_by_xpath('').click()
break
except NoSuchElementException:
pass
except ElementNotInteractableException:
pass

But I am unable to do that in node. This is the error I get:

(node:1544) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element:

How would I be able to do that with node js?

🌐
BugBug
bugbug.io › blog › software testing
How to Handle NoSuchElementException in Selenium?
January 16, 2026 - Sometimes the element is not immediately available because it's loaded after an AJAX call or other asynchronous operations. In such cases, using a custom expected condition might be helpful.
🌐
Google Groups
groups.google.com › g › nodejs › c › FcKrjIxy9Dk
UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element:
September 3, 2018 - await dvr.findElement(By.xpath("//tr[contains(.,'xxx')]")); This will let the findElement function finish executing and return the element object, then assign it to 'elem'. Without the 'await' keyword, 'elem' is a Promise object which doesn't have a method called 'isEmpty'.