Как нажать кнопку «Далее» при входе в почту Yahoo? - PullRequest
1 голос
/ 11 марта 2020

Я пытаюсь войти в Yahoo Mail. Невозможно продолжить, чтобы нажать кнопку «Далее». Я не могу узнать, где мне не хватает. Пожалуйста, ведите меня. Спасибо.

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class FirstScript {
    public static void main (String[] args) {
        System.setProperty("webdriver.chrome.driver","C:\\Selenium\\selenium-java-            3.141.59\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://login.yahoo.com/");                                                                             driver.findElement(By.name("username")).sendKeys("test@yahoo.com"); //name locator for text box
        WebElement searchIcon = driver.findElement(By.name("signin"));//name locator for next button
        searchIcon.click();
        driver.findElement(By.name("password")).sendKeys("testing"); //name locator for text box
        WebElement searchIcon2 =     driver.findElement(By.name("verifyPassword"));//name locator for next button
        searchIcon2.click();
    }
}

Ответы [ 3 ]

1 голос
/ 11 марта 2020

Ваш скрипт правильный. Вам просто нужно подождать, пока экран не перейдет на следующую страницу. Модифицированный скрипт (включая явное ожидание) ниже;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class sample{
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","<driverlocation>");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        WebDriverWait wait = new WebDriverWait(driver,30);
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://login.yahoo.com/");
        driver.findElement(By.name("username")).sendKeys("test@yahoo.com"); // name locator for text box
        WebElement searchIcon = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"login-signin\"]")));// name locator for next button
        searchIcon.click();
        WebElement password = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password")));
        password.sendKeys("testing"); // name locator for text box
        WebElement searchIcon2 = driver.findElement(By.name("verifyPassword"));// name locator for next button
        searchIcon2.click();
    }
}`
0 голосов
/ 11 марта 2020

Я попробовал приведенный ниже код, и все заработало, поэтому стоит попробовать

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("https://login.yahoo.com/");
driver.findElement(By.cssSelector("#login-username")).sendKeys("Test123456789");    
driver.findElement(By.cssSelector("#login-signin")).click();
driver.findElement(By.cssSelector("#login-passwd")).sendKeys("123456");
driver.findElement(By.cssSelector("#login-signin")).click();
0 голосов
/ 11 марта 2020

Чтобы отправить последовательность символов сначала в поле Адрес электронной почты , вызовите click() на кнопке с текстом Далее , отправьте последовательность символов на Пароль и снова вызовите click() на кнопке с текстом Далее , вам нужно вызвать WebDriverWait для elementToBeClickable(), и вы можете использовать следующие стратегии локатора:

  • Блок кода:

    import org.openqa.selenium.By;
    import org.openqa.selenium.JavascriptExecutor;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class A_ChromeTest 
    {
        public static void main(String[] args) 
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            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.navigate().to("https://login.yahoo.com/");
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.phone-no#login-username"))).sendKeys("dev_pspl");
            driver.findElement(By.cssSelector("input#login-signin")).submit();
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#password-container>input"))).sendKeys("test123");
            ((JavascriptExecutor)driver).executeScript("arguments[0].click();", driver.findElement(By.xpath("//button[@id='login-signin']")));
        }
    }
    
  • Снимок браузера:

yahoo_login

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...