Как заполнить поля имени пользователя и пароля на странице входа в Yahoo с помощью Selenium и Java - PullRequest
0 голосов
/ 05 ноября 2019
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");

}   
}

Я пытаюсь ввести имя пользователя и пароль на странице входа в Yahoo. Я могу ввести имя пользователя, но не могу ввести пароль

Ответы [ 2 ]

0 голосов
/ 05 ноября 2019

Чтобы заполнить поля username и password в Yahoo странице входа https://in.yahoo.com/, вам нужно вызвать WebDriverWait дляelementToBeClickable(), и вы можете использовать любой из следующих Стратегий локатора :

  • Блок кода:

    • Использование 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");
      
    • Использование 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");
      
  • Снимок браузера:

yahoo_login

0 голосов
/ 05 ноября 2019

Пожалуйста, найдите ниже решение.

Раствор

    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");
...