0

Error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #passwordNext
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'BRIGHTLEAF-0046', ip: '192.168.0.107', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 59.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 9752, moz:profile: C:\Users\Priti Raut\AppData..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 7982cff0-6252-4eae-9a37-68aa3b6ef83e
*** Element info: {Using=id, value=passwordNext}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)

Code:

package scripts;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class google 
{
    public static void main(String[] args)
    {
        System.setProperty("webdriver.gecko.driver","C:\\Users\\Priti Raut\\Downloads\\geckodriver-v0.20.1-win64\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.manage().deleteAllCookies();
        driver.get("https://mail.google.com/");     

        driver.findElement(By.id("identifierId")).sendKeys("my username"); 
        driver.findElement(By.id("identifierNext")).click();    
        System.out.println("identifier next");
        //driver.findElement(By.name("password")).sendKeys("my password");
        System.out.println("password next");
        driver.findElement(By.id("passwordNext")).click();
        System.out.println("click next");
        driver.quit();
    }       
}

I tried using className as well as using name attribute, but system doesn't accept value for password and next button of password.

  • Please share the HTML of the page, so that proper help can be provided. – Kenil Fadia Aug 27 at 12:48
0

The error is because either the element is dead, due to page refresh or webdriver is unable to locate/it at the specified path before it moves on, so use thread.sleep() method, which will wait for a pre-defined time before throwing an error.

for thread.sleep read this tutorial.

Further recommended reading seleniumhq.org site.

0

There can be a couple reasons to check:

  • Check if the locating strategy is correct.
  • Check if the element is present in the current top level browsing context.(esp. if it is present inside a frame)
  • Sync issue
0

As per the Stack Trace

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: #passwordNext
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:33:08.638Z'
System info: host: 'BRIGHTLEAF-0046', ip: '192.168.0.107', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_161'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 59.0.2, javascriptEnabled: true, moz:accessibilityChecks: false, moz:headless: false, moz:processID: 9752, moz:profile: C:\Users\Priti Raut\AppData..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: XP, platformName: XP, platformVersion: 10.0, rotatable: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}}
Session ID: 7982cff0-6252-4eae-9a37-68aa3b6ef83e
*** Element info: {Using=id, value=passwordNext}

The element passWordNext is not able to be located. If you're using a CSS Selector, then use input#passWordNext otherwise if you're using the id locator, just use passWordNext (without the #), and wait for some time (preferably using an Explicit Wait).

0

Use thread.sleep() before the password field then this will work..

Else use implicitly Wait command before the password field:

driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
  • Do not use thread.sleep(); This is not a good practice, and your test ALWAYS is flaky. Instead use explicit wait. – Zhivko.Kostadinov May 2 '18 at 7:45
  • @Zhivko.Kostadinov - I am sorry that mods converted your correct answer to a comment to an incorrect answer, but this is how it is: "Life is not fair, and then you die" :-) Hang around and try again next time. Good luck! – Peter M. - stands for Monica May 2 '18 at 13:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.