public static void main(String[] args){
System.setProperty("webdriver.chrome.driver","E:/softwares/chromedriver_win32/chromedriver.exe");
WebDriver gmail= new ChromeDriver();
gmail.get("https://www.gmail.co.in");
gmail.findElement(By.id("Email")).sendKeys("abcd");
gmail.findElement(By.id("next")).click();
gmail.findElement(By.id("Passwd")).sendKeys("xyz");
- 462,703
- 120
- 1,088
- 1,195
- 171
- 1
- 1
- 10
-
Welcome to Stack Overflow! What have you tried and what was the result? As you did in school... please show your work. :) It's part of the process of getting questions answered on SO. It's helpful to you because it forces you to investigate your own problem and think it through. It also proves to readers that you did your homework and made a reasonable attempt to answer your own question. Thirdly, it helps readers find and diagnose the problem resulting in a better answer for you and less time wasted for us. – JeffC Oct 24 '15 at 13:46
-
Try setting `gmail.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);` after you create the `ChromeDriver` object. Let me know if this works. – JRodDynamite Oct 24 '15 at 14:18
3 Answers
Try setting an implicit wait of maybe 10 seconds.
gmail.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Or set an explicit wait. An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code. In your case, it is the visibility of the password input field. (Thanks to ainlolcat's comment)
WebDriverWait wait = new WebDriverWait(gmail, 10);
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(By.id("Passwd")));
gmail.findElement(By.id("Passwd")).sendKeys("xyz");
Explanation: The reason selenium can't find the element is because the id of the password input field is initially Passwd-hidden. After you click on the "Next" button, Google first verifies the email address entered and then shows the password input field (by changing the id from Passwd-hidden to Passwd). So, when the password field is still hidden (i.e. Google is still verifying the email id), your webdriver starts searching for the password input field with id Passwd which is still hidden. And hence, an exception is thrown.
- 1
- 1
- 12,325
- 5
- 43
- 63
-
1May be use waitforvisible analog described there http://stackoverflow.com/q/10941184/1003030 . First part of answer is similar to your but explicit condition is more easy to read. – ainlolcat Oct 24 '15 at 20:32
Thread.sleep(); worked for me .
WebDriver driver=new FirefoxDriver();
driver.get("https:www.google.com");
driver.findElement(By.linkText("Gmail")).click();
driver.findElement(By.linkText("SIGN IN")).click();
driver.findElement(By.id("Email")).sendKeys("abcde");
driver.findElement(By.id("next")).click();
Thread.sleep(2000);
WebElement password = driver.findElement(By.xpath(".//*[@id='Passwd']"));
password.sendKeys("xyzzz");
driver.findElement(By.id("signIn")).click();
Thread.sleep(4000);
driver.close();
- 1
- 1
driver.get("http://mail.google.com");
driver.findElement(By.xpath("//input[@id='identifierId']")).sendKeys("emaild");
driver.findElement(By.xpath("//span[contains(text(),'Next')]")).click();
Thread.sleep(2000);
WebElement passwordEnter = driver.findElement(By.xpath("//input[@name='password']"));
passwordEnter.sendKeys(password);
driver.findElement(By.xpath("//span[contains(text(),'Next')]")).click();
- 1
- 1