You can never be sure that element will be found, actually this is purpose of functional tests - to tell you if anything changed on your page. But one thing which definitely helps is to add waits for the elements which are often causing NoSuchElementException like

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));
Answer from Petr Mensik on Stack Overflow
🌐
BrowserStack
browserstack.com › home › guide › understanding no such element exception in selenium
Understanding No Such Element Exception in Selenium | BrowserStack
March 21, 2025 - NoSuchElementException is thrown by the findElement() method in Selenium WebDriver when the desired web element cannot be located using the specified locator, such as ID, name, CSS Selector, or XPath.
Top answer
1 of 10
35

You can never be sure that element will be found, actually this is purpose of functional tests - to tell you if anything changed on your page. But one thing which definitely helps is to add waits for the elements which are often causing NoSuchElementException like

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>));
2 of 10
8

I completely agree to Petr Mensik above. The matter you can never say whether element is present. You should clearly understand why when it happens. From my experience I should say that it happens due to the following reasons:

  • 1) The page is still being rendered and you've already finished your element search and obtain no element exception.
  • 2) The second reason is AJAX has not returned yet and you've already obtain NoSuchElementException
  • 3) The third is most obvious: The element is really not on the page whenever.

so the most robust IMHO way to handle all these three conditions using one function call is to use fluentWait as Amith003 suggested.

so the code be the following:

let ur element has the locator:

String elLocXpath= "..blablabla";
WebElement myButton= fluentWait(By.xpath(elLocXpath));
myButton.click();

public WebElement fluentWait(final By locator){
        Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
                .withTimeout(30, TimeUnit.SECONDS)

                .pollingEvery(5, TimeUnit.SECONDS)

        .ignoring(org.openqa.selenium.NoSuchElementException.class);
        WebElement foo = wait.until(
                new Function<WebDriver, WebElement>() {
                    public WebElement apply(WebDriver driver) {
                        return driver.findElement(locator);
                    }
                }
        );
        return  foo;
    };

Also if your purpose is robust code wrap fluentWait() with a try{} catch{} block.

Also don't forget about

 public boolean isElementPresent(By selector)
   {

              return driver.findElements(selector).size()>0;
}

that is also useful.

So to conclude all the mentioned if you want to avoid NoElement exception just handle it properly as nobody can ensure in the element presence on the page.

Hope now it is more clear to you. Regards

Discussions

selenium.common.exceptions.NoSuchElementException Error : Forums : PythonAnywhere
Examine the html of the response ... expected element is not there. glenn | 10384 posts | PythonAnywhere staff | Nov. 13, 2020, 10:40 a.m. | permalink · Good afternoon! I'm trying to run a script on your server. The script works with Selenium. And everything was fine at first, but during the program the code crashes and gives the error No Such ... More on pythonanywhere.com
🌐 pythonanywhere.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
Selenium Python - Handling No such element exception - Stack Overflow
I am writing automation test in Selenium using Python. One element may or may not be present. I am trying to handle it with below code, it works when element is present. But script fails when eleme... More on stackoverflow.com
🌐 stackoverflow.com
Selenium Python NoSuchElementException
10.2k members in the selenium community. Users forum for selenium browser testing. Do not advertise here. More on reddit.com
🌐 r/selenium
June 23, 2020
🌐
Selenium
selenium.dev › documentation › webdriver › troubleshooting › errors
Understanding Common Errors | Selenium
This exception occurs when Selenium tries to interact with an element that is not interactable in its current state. Unsupported Operation: Performing an action, like sendKeys, on an element that doesn’t support it (e.g., <form> or <label>). ...
🌐
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).
🌐
Reflect
reflect.run › articles › everything-you-need-to-know-about-nosuchelementexception-in-selenium
Everything you need to know about NoSuchElementException in Selenium | Reflect
This would not possible without first locating and retrieving these elements on the page. When the process of locating the elements of interest in the web page fails, Selenium throws a NoSuchElementException.
🌐
Educative
educative.io › answers › what-is-nosuchelementexception-in-selenium-python
What is `NoSuchElementException` in Selenium-Python?
When we try to find any element in an HTML page that does not exist, NoSuchElementException will be raised. selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","sel...
Find elsewhere
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 28682
selenium.common.exceptions.NoSuchElementException Error : Forums : PythonAnywhere
Examine the html of the response ... expected element is not there. glenn | 10384 posts | PythonAnywhere staff | Nov. 13, 2020, 10:40 a.m. | permalink · Good afternoon! I'm trying to run a script on your server. The script works with Selenium. And everything was fine at first, but during the program the code crashes and gives the error No Such ...
🌐
BugBug
bugbug.io › blog › software testing
How to Handle NoSuchElementException in Selenium?
January 16, 2026 - By combining these strategies, ... your Selenium tests more robust and resilient to dynamic web pages. Let me know if you'd like code examples or further clarification on any of these points! ... Test easier than ever with BugBug test recorder. Faster than coding. Free forever. ... You can use the throw statement in Java to manually trigger the NoSuchElementException. For instance, if a condition is not met (such as an element not being found), you can throw the exception to simulate ...
🌐
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 ...
🌐
Letskodeit
letskodeit.com › blog › no-such-element-exception
No Such Element Exception - Selenium WebDriver Tutorial
This issue often occurs when the web application relies heavily on dynamic content or asynchronous behavior. To handle timing-related NoSuchElementExceptions, you can implement wait mechanisms in your test scripts.
🌐
Quora
quora.com › How-do-I-resolve-NoSuchElementException-in-Selenium-Java
How to resolve NoSuchElementException in Selenium Java - Quora
Answer: It is as simple as Exception says i.e. there is No Such Element present on the page which you’ve directed selenium to identify and act upon. org.openqa.selenium.NoSuchElementException So again, to resolve this you have to help- Selenium recognizing the element you intended. By providing...
🌐
Coderanch
coderanch.com › t › 680348 › engineering › element-exception-Selenium
No such element - exception Selenium (Testing forum at Coderanch)
Hi Dana, As the exception name would indicate, NoSuchElementException, usually means that the element wasn't present on the page when Selenium attempted to find it. (Link here to the org.openqa.selenium.NoSuchElementException API as the link above will go to java.util.NoSuchElementException ).
🌐
Virtuoso QA
virtuosoqa.com › post › no-such-element-exception-selenium
NoSuchElementException in Selenium: Cause + Fix
February 12, 2026 - Unlike StaleElementReferenceException (where the element was found but became invalid), NoSuchElementException means Selenium never successfully located the element in the first place.
🌐
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

🌐
Skillrary
skillrary.com › blogs › read › how-to-handle-nosuchelement-exception-in-java-selenium
How to handle NoSuchElement Exception in Java Selenium | SkillRary
March 3, 2020 - Consider that in the below example, correct XPath expression for the Login button was //div[.='Login '] but the tester incorrectly mentioned it as //div[.='Login'] if you observe, the tester has forgotten to give space after login word as in this case, space is also a character. Here, WebDriver cannot locate the element and org.openqa.selenium. NoSuchElementException will be thrown by driver.findElement(By.xpath("//div[.='Login']")).click();
🌐
Blogger
selenium-by-arun.blogspot.com › 2017 › 05 › nosuchelementexception-webdriver.html
Selenium-By-Arun: NoSuchElementException WebDriver Exception
Hence NoSuchElementException Exception will be occurred, when the locators (i.e. id / xpath/ css selectors etc) we mentioned in the Selenium Program code is unable to find the web element on the web page and in order to handle this, we have ...
🌐
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. In the next examples, we see how to fix this NoSuchElementException in Selenium.
Published   February 17, 2026
🌐
testRigor
testrigor.com › home › blog › notfoundexception in selenium explained
NotFoundException in Selenium Explained - testRigor AI-Based Automated Testing Tool
December 14, 2023 - In Selenium, NotFoundException is raised when it cannot locate the element on the web page based on the specified selector or criteria. This exception typically occurs when we use the Selenium methods like “findElement” or “findElements” ...