0
package newproject;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;



public class Amazon {

public static void main(String[] args) throws InterruptedException {


String url = ("https://in.yahoo.com/"); 

System.setProperty("webdriver.chrome.driver", 
"F:\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(url);
driver.manage().deleteCookieNamed(url);
driver.navigate().forward();
driver.manage().window().maximize();
driver.findElement(By.id("uh-signin")).click();
driver.findElement(By.id("login-username")).sendKeys("myemail@yahoo.com"); 
Thread.sleep(2000);
driver.navigate().forward();
driver.findElement(By.id("login-signin")).click();
//driver.findElement(By.name("password")).click();
driver.findElement(By.id("login-passwd")).sendKeys("...");
//System.out.print("You are welcome");

}   
}

I am trying to enter username and password in yahoo login page i am able to enter the username but not able to enter password

Greg Burghardt
  • 14,951
  • 7
  • 38
  • 71
  • insufficient details. Share what page of yahoo you are accessing. – Vinay Prajapati Nov 05 '19 at 10:01
  • I am trying to sign in on "https://in.yahoo.com/" using the sign-in button I am able to enter a username but when the browser clicks on password through send-keys it does not proceed further. – Ajay Singh Nov 05 '19 at 10:05
  • Is it not entering the password or unable to proceed. If it is unable to proceed it might be case if password is wrong. Or you are not clicking the sign -in button below the password – Sahit Nov 05 '19 at 10:18
  • Yes this is not entering the password – Ajay Singh Nov 05 '19 at 10:19
  • Add a time delay with Thread.sleep() and see if it works.. it might be a case after clicking the Next button the password page is loading slow and it is unable to find element with the id. – Sahit Nov 05 '19 at 10:26
  • Still not entering the password after adding a time delay – Ajay Singh Nov 05 '19 at 10:31
  • Are you getting an exception? Is so, please add that to you question, including the stack trace. – Greg Burghardt Nov 06 '19 at 23:28

2 Answers2

0

Please find the below solution.

Solution

    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    //driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
    driver.get("https://in.yahoo.com/");



    driver.findElement(By.xpath("//button[@name='agree']")).click();
    driver.findElement(By.xpath("//a[@id='uh-signin']")).click();

    driver.findElement(By.id("login-username")).sendKeys("Thakur_aju2008@yahoo.com");
    driver.findElement(By.id("login-signin")).click();
    Thread.sleep(5000);

    driver.findElement(By.xpath("//input[@id='login-passwd']")).sendKeys("Pranavpooja@2017");
Dipak Bachhav
  • 3,579
  • 1
  • 5
  • 19
0

To fill up the username and password fields within the Yahoo login page https://in.yahoo.com/ you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • Code Block:

    • Using cssSelector:

      ChromeOptions options = new ChromeOptions();
      options.addArguments("start-maximized");
      //options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
      //options.setExperimentalOption("useAutomationExtension", false);
      WebDriver driver = new ChromeDriver(options);
      driver.get("https://in.yahoo.com/");
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#uh-signin"))).click();
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.phone-no"))).sendKeys("Thakur_aju2008@yahoo.com");
      driver.findElement(By.cssSelector("input#login-signin")).click();
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#login-passwd"))).sendKeys("Pranavpooja@2017");
      
    • Using xpath:

      ChromeOptions options = new ChromeOptions();
      options.addArguments("start-maximized");
      //options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
      //options.setExperimentalOption("useAutomationExtension", false);
      WebDriver driver = new ChromeDriver(options);
      driver.get("https://in.yahoo.com/");
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@id='uh-signin']"))).click();
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='phone-no ']"))).sendKeys("Thakur_aju2008@yahoo.com");
      driver.findElement(By.xpath("//input[@id='login-signin']")).click();
      new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='login-passwd']"))).sendKeys("Pranavpooja@2017");
      
  • Browser Snapshot:

yahoo_login

DebanjanB
  • 118,661
  • 30
  • 168
  • 217