Thank you for all answers. I found solution to my problem. The last command was command which was linked with IFrame

WebElement editorFrame = driver.findElement(By.cssSelector("#sentmsgcomposeEditor_ifr"));
   driver.switchTo().frame(editorFrame);

   WebElement body1 = driver.findElement(By.tagName("body"));
   body1.sendKeys(Keys.CONTROL + "a"); 

So i was in IFrame actually because of it i couldn't find any element. I performed following command:

 driver.switchTo().defaultContent();

After that it is possible to find locators.

Answer from Bilow Yuriy on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › unable-to-locate-an-element-using-xpath-error-in-selenium-java
Unable to locate an element using xpath error in selenium-java
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class XpathError{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); //launch URL driver.get("https://www.tutorialspoint.com/index.htm"); WebElement m = driver.findElement(By.xpath("//*[text()='Library']")); m.click(); //explicit wait condition - visibilityOfElementLocated w.until(ExpectedConditions.visibilityOfElementLocated (By.linkText("Subscribe to Premium"))); System.out.println("Page title: " + driver.getTitle()); driver.quit(); } }
🌐
Google Groups
groups.google.com › g › selenium-users › c › OMgZGydnn0I
Xpath Correct but still get no such element: Unable to locate element:
FileInputStream urlFile = new FileInputStream("C:\\Users\\Ashish\\Documents\\Selenium\\SeleniumPracticeSite\\src\\URL.properties"); ... myDynamicElement.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@name='userName']"))); ... <tr> <td align="right"><font face="Arial, Helvetica, sans-serif" size="2">User Name: </font></td> <td width="112"> <input type="text" name="userName" size="10"> </td> ... http://stackoverflow.com/questions/39561188/xpath-is-correct-still-get-no-such-element-unable-to-locate-element?noredirect=1#comment66434922_39561188
Discussions

Can't get element by XPATH
You're using an absolute xpath, which is almost always a bad idea. This xpath might work at one point, but it's also very prone to failure with even the slightest change in the page's DOM structure. Try coming up with an xpath that more uniquely identifies the element instead of tracing it all the way back to the html tag. More on reddit.com
🌐 r/selenium
4
2
December 4, 2021
selenium - Webdriver Automation - Unable to find element using xpath - Stack Overflow
Environment: Eclipse - Java - Junit - firefox webdriver Screen shot url : https://www.dropbox.com/s/26fl2l1y1mkpxiz/Screenshot 2014-01-06 01.52.43.png I am trying to test a webpage but unable... More on stackoverflow.com
🌐 stackoverflow.com
Selenium Java unable to locate element using xpath - Stack Overflow
Isn't that obvious ? the return type of getElementsTextList method is ArrayList, basically this list eleTextList. However I have provided you a generic solution to handle multiple web elements. I have edited my answer for xpath 2021-05-04T11:45:58.237Z+00:00 More on stackoverflow.com
🌐 stackoverflow.com
Cannot find element by XPATH although it is there.
from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains import undetected_chromedriver as uc def basic_login(email, password): driver = uc.Chrome() driver.get(" https://turo.com/ca/en/login ") email_field  = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, """email"""))) email_field.send_keys(email) password_field = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, """password"""))) password_field.send_keys(email) # Find the button using its data-testid attribute button = driver.find_element(By.CSS_SELECTOR, '[data-testid="submitLoginButton"]') # Click the button button.click() if __name__ == '__main__': email= '' password='' basic_login(email, password) More on reddit.com
🌐 r/selenium
1
3
June 3, 2023
🌐
Quora
quora.com › How-do-you-handle-being-unable-to-locate-an-element-in-Selenium
How to handle being unable to locate an element in Selenium - Quora
Answer: Hello, 1. Check in the event that there is any language structure mistake in our xpath expression. 2. Add extra expected wait conditions for the element. 3. Utilize an option xpath expression.
🌐
Reddit
reddit.com › r/selenium › can't get element by xpath
r/selenium on Reddit: Can't get element by XPATH
December 4, 2021 -

Hello guys,

I'm trying to interact with the interative menu of this page in order to automate several data downloads instead of making it by hand.

The thing is that when I copy an XPATH of a selector (for example when I try to get the XPATH of the "Commodities" menu), selenium says:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[9]/div[1]/div[3]/ul/li[6]"}

Does anyone know why I can't get the element?

Thank you all in advance!

EDIT WITH SOLUTION:

The problem was that items I want to find are inside an iframe. So I have to switch the context of the webdriver first. Code with the solution:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get('https://www.dukascopy.com/swiss/english/marketwatch/historical/')

table = driver.find_element(By.XPATH, '/html/body/div/main/div[2]/div/div/div/p[3]/iframe')

driver.switch_to.frame(table)

driver.find_element(By.XPATH, '/html/body/div[9]/div[1]/div[3]/ul/li[13]').click()

🌐
Stack Overflow
stackoverflow.com › questions › 67382575 › selenium-java-unable-to-locate-element-using-xpath
Selenium Java unable to locate element using xpath - Stack Overflow
You need to tweak your xpath bit, use the below to get exact Machine name : ... new WebDriverWait(driver, timeout).ignoring(StaleElementReferenceException.class).until(ExpectedConditions.visibilityOfElement(locator));
Find elsewhere
🌐
Reddit
reddit.com › r/selenium › cannot find element by xpath although it is there.
r/selenium on Reddit: Cannot find element by XPATH although it is there.
June 3, 2023 -

Hey guys, new to the community and new to using Selenium. Can I please have some help? I am using Python and Selenium for navigating through a website. The website is turo.com; my goal is to login using my code.

So far, I am able to open the website, navigate to the "log in" button and click on it. After the login button is clicked, there is a modal that pops up with 2 input fields for email/user and password. I have the XPATH to the input fields but they are not working. I get the following error message:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"html/body/div[1]/form/div[1]/input[@id="email"]"}

Please let me know how to debug this error. I have tried stackoverflow and other forums but no answer so far. Thank you!

EDIT: I have tried using '//input[@data-testid="email"]' as well.

🌐
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 ... element cannot be found. A NoSuchElementException occurs when the Selenium locator strategy defined is unable to find the desired HTML element in the web page....
🌐
BrowserStack
browserstack.com › home › guide › find element by xpath in selenium in 2026
How to find element by XPath in Selenium [2026] | BrowserStack
December 19, 2025 - Many testers assume XPath in Selenium is easy—inspect an element, copy the XPath, and move on. I thought the same until a minor UI update broke half my tests in one run. Suddenly, every copied XPath failed, and I spent hours regenerating locators that kept breaking again.
🌐
Stack Overflow
stackoverflow.com › questions › 23927510 › unable-to-locate-an-element-with-the-xpath-expression
java - Unable to locate an element with the xpath expression - Stack Overflow
... I would suggest you to identify the element which is above/below/next to the element which you are looking for with text and using xpath methods like following-sibling/preceding methods and identify the element..
🌐
Edureka Community
edureka.co › home › community › categories › selenium › not able to find element with xpath
Not able to find element with Xpath | Edureka Community
July 4, 2018 - Selenium Webdriver Java - Eclipse java lang NoClassDefFoundError Oct 1, 2024 ... "Error: Unable to initialize main class Commands.Getcommands Caused by: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver" how to resolve this?
🌐
Quora
quora.com › In-Selenium-WebDriver-after-the-launching-browser-I-am-getting-an-error-as-unable-to-locate-element-even-if-the-locator-is-correct-What-can-be-done-to-be-successful
In Selenium WebDriver, after the launching browser, I am getting an error as unable to locate element even if the locator is correct. What can be done to be successful? - Quora
Answer (1 of 10): Check the following things:- 1. Check whether you are trying to locate web element in the correct frame. If not switch the frame and then try to locate it. 2. Make sure you are using the correct by class methods for your locator.
🌐
GitHub
github.com › seleniumhq › selenium-google-code-issue-archive › issues › 5047
Unable to locate element: {"method":"xpath","selector":"//*[@id='usernameTextEdit']"} · Issue #5047 · SeleniumHQ/selenium-google-code-issue-archive
March 4, 2016 - ----------------------------------------------------------- public class Login { public static void main(String[] args) { WebDriver d1= new FirefoxDriver(); d1.navigate().to("http://inlv50795915s:8080/InfoViewApp"); d1.findElement(By.xpath("//*[@id='usernameTextEdit']")).sendKeys("administrator"); } } --------------------------------------------------------------- Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='usernameTextEdit']"} Command duration or timeout: 188 milliseconds For documentation on this erro
Author   lukeis
Top answer
1 of 4
45

NoSuchElementException

org.openqa.selenium.NoSuchElementException popularly known as NoSuchElementException extends org.openqa.selenium.NotFoundException which is a type of WebDriverException.

NoSuchElementException can be thrown in 2 cases as follows :

  • When using WebDriver.findElement(By by) :

    //example : WebElement my_element = driver.findElement(By.xpath("//my_xpath"));
    
  • When using WebElement.findElement(By by) :

    //example : WebElement my_element = element.findElement(By.xpath("//my_xpath"));
    

As per the JavaDocs just like any other WebDriverException, NoSuchElementException should contain the following Constant Fields :

Constant Field      Type                                        Value
SESSION_ID          public static final java.lang.String        "Session ID"
e.g. (Session info: chrome=63.0.3239.108)

DRIVER_INFO         public static final java.lang.String        "Driver info"
e.g. (Driver info: chromedriver=2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1),platform=Windows NT 6.1.7601 SP1 x86)

BASE_SUPPORT_URL    protected static final java.lang.String     "http://seleniumhq.org/exceptions/"
e.g. (For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html)

Reason

The reason for NoSuchElementException can be either of the following :

  • The Locator Strategy you have adopted doesn't identifies any element in the HTML DOM.
  • The Locator Strategy you have adopted is unable to identify the element as it is not within the browser's Viewport.
  • The Locator Strategy you have adopted identifies the element but is invisible due to presence of the attribute style="display: none;".
  • The Locator Strategy you have adopted doesn't uniquely identifies the desired element in the HTML DOM and currently finds some other hidden / invisible element.
  • The WebElement you are trying to locate is within an <iframe> tag.
  • The WebDriver instance is looking out for the WebElement even before the element is present/visibile within the HTML DOM.

Solution

The solution to address NoSuchElementException can be either of the following :

  • Adopt a Locator Strategy which uniquely identifies the desired WebElement. You can take help of the Developer Tools (Ctrl+Shift+I or F12) and use Element Inspector.

    Here you will find a detailed discussion on how to inspect element in selenium3.6 as firebug is not an option any more for FF 56?

  • Use executeScript() method to scroll the element in to view as follows :

    WebElement elem = driver.findElement(By.xpath("element_xpath"));
    ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView();", elem);
    

    Here you will find a detailed discussion on Scrolling to top of the page in Python using Selenium

  • Incase element is having the attribute style="display: none;", remove the attribute through executeScript() method as follows :

    WebElement element = driver.findElement(By.xpath("element_xpath"));
    ((JavascriptExecutor)driver).executeScript("arguments[0].removeAttribute('style')", element)
    element.sendKeys("text_to_send");
    
  • To check if the element is within an <iframe> traverse up the HTML to locate the respective <iframe> tag and switchTo() the desired iframe through either of the following methods :

    driver.switchTo().frame("frame_name");
    driver.switchTo().frame("frame_id");
    driver.switchTo().frame(1); // 1 represents frame index
    

    Here you can find a detailed discussion on Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?.

  • If the element is not present/visible in the HTML DOM immediately, induce WebDriverWait with ExpectedConditions set to proper method as follows :

    • To wait for presenceOfElementLocated :

      new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
      
    • To wait for visibilityOfElementLocated :

      new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
      
    • To wait for elementToBeClickable :

      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='buttonStyle']//input[@id='originTextField']")));
      

Reference

You can find Selenium's python client based relevant discussion in:

  • Selenium “selenium.common.exceptions.NoSuchElementException” when using Chrome
2 of 4
3

Your code is correct, I suspect the issue caused the page not complete load when you find the element.

Try add a long sleep before find element, if adding sleep worked, change sleep to wait.

Here is the code, It means waiting 10s if the element isn’t present:

element = WebDriverWait(driver, 10).until(
    EC.presence_of_element_located((By.ID, "originTextField"))
)