This error message...

Sun Sep 22 18:13:27 IDT 2019:ERROR: no such element: Unable to locate element: {"method":"id","selector":"//input[@id='company']"}
  (Session info: chrome=76.0.3809.132)
  (Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86_64)

...implies that the ChromeDriver was unable to locate the desired element.

There are a couple of things which you need to take care:

  • The Locator Strategy which you have used isn't the id, but it's the xpath
  • Though you are using chrome=76.0 but chromedriver=2.36 is too old.

Solution

  • For the selector value of //input[@id='company'] change the method as "xpath".
  • Ensure JDK is upgraded to current levels JDK 8u222.
  • Ensure Selenium is upgraded to current levels Version 3.141.59.
  • Ensure ChromeDriver is updated to current ChromeDriver v77.0 level.
  • Chrome is updated to current Chrome Version 77.0 level. (as per ChromeDriver v77.0 release notes)
Answer from undetected Selenium on Stack Overflow
🌐
Reddit
reddit.com › r/selenium › selenium can't find element with id/name
r/selenium on Reddit: Selenium can't find element with ID/Name
August 9, 2022 -

Im trying to challenge myself by making selenium redeem 1 gamepass code on microsoft issue is I Found the ID but it doesn't work as in Selenium can't find it, This is the website I need selenium to recognize and type in it

this is the error

Traceback (most recent call last):

File "c:\Users\jeans\Downloads\New folder\Microsoft\redeem.py", line 30, in <module>

gamepass = driver.find_element(By.ID, value="tokenString")

File "C:\Users\jeans\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 857, in find_element

return self.execute(Command.FIND_ELEMENT, {

File "C:\Users\jeans\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute

self.error_handler.check_response(response)

File "C:\Users\jeans\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response

raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="tokenString"]"}

(Session info: chrome=104.0.5112.81)

Stacktrace:

Backtrace:

Ordinal0 [0x00FA78B3+2193587]

Ordinal0 [0x00F40681+1771137]

Ordinal0 [0x00E541A8+803240]

Ordinal0 [0x00E824A0+992416]

Ordinal0 [0x00E8273B+993083]

Ordinal0 [0x00EAF7C2+1177538]

Ordinal0 [0x00E9D7F4+1103860]

Ordinal0 [0x00EADAE2+1170146]

Ordinal0 [0x00E9D5C6+1103302]

Ordinal0 [0x00E777E0+948192]

Ordinal0 [0x00E786E6+952038]

GetHandleVerifier [0x01250CB2+2738370]

GetHandleVerifier [0x012421B8+2678216]

GetHandleVerifier [0x010317AA+512954]

GetHandleVerifier [0x01030856+509030]

Ordinal0 [0x00F4743B+1799227]

Ordinal0 [0x00F4BB68+1817448]

Ordinal0 [0x00F4BC55+1817685]

Ordinal0 [0x00F55230+1856048]

BaseThreadInitThunk [0x76CEFA29+25]

RtlGetAppContainerNamedObjectPath [0x779B7A9E+286]

RtlGetAppContainerNamedObjectPath [0x779B7A6E+238]

🌐
DEV Community
dev.to › liviufromendtest › how-to-fix-the-element-not-found-error-in-selenium-28gj
How to fix the "Element not found" error in Selenium - DEV Community
July 13, 2020 - If we take a closer look at that element, we can see that it has a stable Name attribute. So, the solution would be to use the Name attribute as the locator: username_input = driver.find_element_by_name("username") username_input.send_keys(...
Discussions

NoSuchElementException, Selenium unable to locate element - Stack Overflow
Constant Field Type Value SESSION_ID ... http://seleniumhq.org/exceptions/no_such_element.html) 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 ... More on stackoverflow.com
🌐 stackoverflow.com
java - Unable to locate an Element By ID in Selenium - Stack Overflow
I am having trouble locating the login id using selenium. I got this work on a windows computer before, but I am trying to do this at home on my mac and I am not able to find the element by id anym... More on stackoverflow.com
🌐 stackoverflow.com
java - Selenium unable to locate element by id/name - Stack Overflow
This question has been asked many times, but none of the answers seem to work. I am trying to simply locate the search bar on the google front page (https://google.com). If looking at the inspector... More on stackoverflow.com
🌐 stackoverflow.com
Selenium cannot locate any elements
🐛 Bug Report Selenium cannot locate any elements on web app (Oracle's Customer Care & Billing - CC&B). The issue occures only on this web app. Exception in thread "main" org.o... More on github.com
🌐 github.com
12
August 9, 2021
🌐
Selenium
selenium.dev › documentation › webdriver › troubleshooting › errors
Understanding Common Errors | Selenium
You may have used a CSS or XPATH selector as a parameter to an ID selector. ... The element can not be found at the exact moment you attempted to locate it.
🌐
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.
🌐
Reflect
reflect.run › articles › everything-you-need-to-know-about-nosuchelementexception-in-selenium
Everything you need to know about NoSuchElementException in Selenium | Reflect
The Selenium By class allows you to define the locator strategy that Selenium will apply to find HTML elements within a web document. When Selenium fails to find the HTML element identified with the By condition, a NoSuchElementException is thrown.
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"))
)
Find elsewhere
🌐
GitHub
github.com › seleniumhq › selenium-google-code-issue-archive › issues › 3032
NoSuchElementException in IE7 when attempting to Find a WebElement By ID · Issue #3032 · SeleniumHQ/selenium-google-code-issue-archive
I expect the WebElement to be located by it's id, instead a NoSuchElementException is being thrown. Selenium version: 2.0.15 OS: Windows XP SP3 Browser: IE Brower version: 7 Exception org.openqa.selenium.NoSuchElementException: Unable to find element with id == browserNameTextBoxID (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 312 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.15.0', revision: '15105', time: '2011-12-08 12:59:39' System info: os.name: 'Wind
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 69416947 › selenium-unable-to-locate-element-by-id-name
java - Selenium unable to locate element by id/name - Stack Overflow
"Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element with name: q" ... package pack; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.htmlunit.HtmlUnitDriver; public class Klasse { public static void main(String[] args) { WebDriver driver = new HtmlUnitDriver(); driver.get("https://www.google.com/"); driver.findElement(By.name("q")); } }
🌐
Google Groups
groups.google.com › g › selenium-users › c › OMgZGydnn0I
Xpath Correct but still get no such element: Unable to locate element:
website http://newtours.demoaut.com/ I am trying to locate login page and send login id. Error: 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']} package SeleniumPracticePackage; 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.chrome.ChromeOptions; import org.
🌐
GitHub
github.com › SeleniumHQ › selenium › issues › 9729
Selenium cannot locate any elements · Issue #9729 · SeleniumHQ/selenium
August 9, 2021 - Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #[Element_Id] Only firefox is compatible with CC&B · driver.findElement(By.id("[Element_Id]")) driver.switchTo().frame("[Frame_Name]"); Finding element to continue script ·
Author   bartekjujka
🌐
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
🌐
Reddit
reddit.com › r/softwaretesting › selenium not recognizing element by id :(
r/softwaretesting on Reddit: Selenium not recognizing element by ID :(
May 1, 2023 -

EDIT:

I solved it thanks to the help of the redditors here. Turns out, it had a dynamic id, which changes each time. I had to use the name in order to properly identify it, like this:

 driver.findElement(By.name("firstname"));

Hello

I'm trying to learn Selenium, and thus I have used a website designed for that. After trying a few different things, I have a user flow almost ready. However, when it comes to the checkout (you can find it at https://magento.softwaretestingboard.com/checkout/#shipping ), I try to select the different fields in order to input data in them, after the first one (email, the only ID with actual words in it), it doesn't recognize the IDs, despite me double and triple checking to make sure they are correctly entered.

Googling my problem, I read it could be because some elements haven't fully loaded, but even after using sleep(10) it still doesn't find them, throwing the error "Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="XS4WH19"]"}".

Not sure if it's helpful, but here's what I get when I inspect the element.

<input class="input-text" type="text" data-bind="
    value: value,
    valueUpdate: 'keyup',
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': getDescriptionId(),
        'aria-required': required,
        'aria-invalid': error() ? true : 'false',
        id: uid,
        disabled: disabled
    }" name="firstname" aria-required="true" aria-invalid="false" id="XS4WH19">

Thanks a lot for your help :)

🌐
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
Add additional expected wait conditions for the element. Use an alternative xpath expression. 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.Ex...
🌐
Python Forum
python-forum.io › thread-38095.html
Selenium suddenly fails to find element
September 2, 2022 - Hello, A strange phenomenon occurred when using Selenium: after several successful executions, the command that searches for a particular element fails. Before Selenium I worked wit BeautifulSoap and also observed such phenomena. Here is code: from...