-1

I'm using Selenium Web driver with Java code. Whenever org.openqa.selenium.NoSuchElementException occurs, stack trace prints identifier method as css selector every time although I have used id to find web element.

I tried using xpath identifier and it prints perfect stack trace with correct identifier method. My sample code.

public void testMethod()
{
    try
    {
        driver.findElement(By.id("test"));
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

Stack trace output:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#test"}
  (Session info: chrome=75.0.3770.100)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:19:58.91Z'
System info: host: 'DTB150', ip: '10.37.55.150', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 75.0.3770.100, chrome: {chromedriverVersion: 75.0.3770.90 (a6dcaf7e3ec6f..., userDataDir: C:\Users\DEV~1.SOL\AppData\...}, goog:chromeOptions: {debuggerAddress: localhost:38152}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: b6c8f6cd722e746281dd59657850e10f
*** Element info: {Using=id, value=test}

Check method in first line of exception. It says method: css selector although I'm using id to find element.

Is that some kind of error or I have misunderstood something or some problem with my code?

Dev Solanki
  • 109
  • 1
  • 8

1 Answers1

0

See the exception : Unable to locate element: {"method":"css selector","selector":"#test"}

in css selector # represent an id.

If id is test and you are using it like this :

driver.findElement(By.id("test"));

Exception should be related to id if not found.

But if you are using it like

driver.findElement(By.cssSelector("#test"));

You would get the same exception as mentioned above in OP.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38