-1

I got this exception or error when I rum my script:

"Unable to locate element: *[name='password']"

I have tried with different locators but every time I get the same error.

Here is my script

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
//import org.openqa.selenium.chrome.ChromeDriver;


public class TestGmail {
    public static void main(String[] args){
        System.setProperty("webdriver.gecko.driver", "E:\\geckodriver-v0.16.0-win32\\geckodriver.exe");

        WebDriver driver=new FirefoxDriver();

        //System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\chromedriver_win32\\chromedriver.exe");

        //WebDriver driver=new ChromeDriver();
        driver.get("https://accounts.google.com/");
        driver.findElement(By.id("identifierId")).sendKeys("myAddress");
        driver.findElement(By.cssSelector("span.RveJvd.snByac")).click();


        driver.findElement(By.name("password")).sendKeys("myPassword");

        driver.findElement(By.className("RveJvd snByac")).click();

        driver.close();
    }


   }
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
nirmala
  • 39
  • 1
  • 1
  • 10

4 Answers4

0

Here is the code block to locate the password field and send text into the password field on the url https://accounts.google.com/

package demo;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class GMAIL_LOGIN_FIREFOX_CSS 
{
    public static void main(String[] args) 
    {
        System.setProperty("webdriver.gecko.driver","C:\\Utility\\BrowserDrivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        String url = "https://accounts.google.com/signin";
        driver.get(url);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
        driver.findElement(By.cssSelector("#identifierId")).sendKeys("your_email");
        driver.findElement(By.cssSelector(".ZFr60d.CeoRYc")).click();
        WebElement password = driver.findElement(By.cssSelector("input[class='whsOnd zHQkBf'][type='password']"));
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.elementToBeClickable(password));
        password.sendKeys("your_password");
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-1

Try this script it is workig fine:

WebDriver driver = new FirefoxDriver();
driver.get("https://accounts.google.com/");
driver.findElement(By.id("identifierId")).sendKeys("myAddress");
driver.findElement(By.cssSelector("span.RveJvd.snByac")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.name("password")).sendKeys("myPassword");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
driver.close();
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
  • Try this @Nirmala in ur main() function it is worked fine – iamsankalp89 Aug 28 '17 at 07:03
  • I have tried its working fine in chrome but not in Firefox. I am using selenium 3.4.0, geckodriver-v0.16.0-win32 and firefox 47. Could there be any issue with installation? – nirmala Aug 28 '17 at 07:46
  • what problem u face in firefox. are u add geckodriver – iamsankalp89 Aug 28 '17 at 07:47
  • Update browser to Firefox 53.0 I guess that is an issue – iamsankalp89 Aug 28 '17 at 07:49
  • "addons.manager ERROR startup failed: [Exception... "Component returned failure code: 0x80070057" I have ignored this before as it was identifying username and next button. – nirmala Aug 28 '17 at 07:50
  • Update your browser and gecko driver it resolved the issue, you have to geckodriver 18 i guess, if code is running in chrome it may be issue of Driver and Browser in FF – iamsankalp89 Aug 28 '17 at 07:54
-1

I would suggest you to use Explicit wait. Using implicit wait is a bad practice.

You can use below code something like below-

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("someid")));

Above code is in Java.

Kapil
  • 397
  • 4
  • 6
-1

Use this code line for finding the "password" element and entering the password

Code is as follows:

driver.findElement(By.Xpath("html/body/div/div/div[2]/div[2]/form/div[2]/div/div/div[1]/div[1]/div/div[1]/div/div[1]/input")).sendKeys("Your password ")
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36