首页 文章

Gmail密码 - 我在PAssword中找不到Xpath,代码是写但不是正确密码[复制]

提问于
浏览
0

这个问题在这里已有答案:

package Login;
 import org.openqa.selenium.By;
 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 Login 
 {
    public static void main(String[] args) throws Exception 
    {
        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Teknomines-5\\Downloads\\chromedriver.exe");
        WebDriver driver=new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com/intl/en-GB/gmail/about/");
        //Thread.sleep(5000);
        driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
        driver.findElement(By.xpath("//*[@id=\"identifierId\"]")).sendKeys("Pratik.modh24@gmail.com");
        driver.findElement(By.xpath("//*[@id=\"identifierNext\"]")).click();

//下面代码密码不能在PAssword文本框上打印//driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/ DIV [2] / DIV / DIV [1] / DIV /形式/内容/部分/ DIV /内容/ DIV [1] / DIV / DIV [1] “))的SendKeys(” 123" ); //driver.findElement(By.className("whsOnd zHQkBf“)) . sendKeys(”123“); //driver.findElement(By.id("Passwd")).sendKeys("test123" ); //driver.findElement(By.name("password")).sendKeys("123" ); //driver.findElement(By.xpath(".//[@id='Passwd']")).sendKeys("123456789" ); //driver.findElement(By.cssSelector("#password> div:nth-child(1)“)) . sendKeys(”123“); //driver.findElement(By.xpath("//INPUT[@name='password']")).sendKeys("**“); //driver.findElement(By.xpath("//INPUT[@type='password']/self::INPUT")).sendKeys("“); //driver.findElement(By.xpath("(//DIV[@class='aCsJod oJeWuf'])[1]“)) . sendKeys(”123456“);

WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(password));
        password.sendKeys("your_password");     
    }

}

2 回答

  • 0

    这个XPATH应该选择gmail "password input": //input[@name='password']

    但是您不必使用XPATH,您可以通过许多其他方式来定位输入字段 . 例如,我正在使用它(在Python中):

    WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.NAME, 'password'))).send_keys('my_password')
    

    EDIT :还可以尝试将命令的顺序更改为:

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']")));
    password.sendKeys("your_password");
    

    因为您在等待它出现在DOM上之前创建了密码变量 WebElement password = driver.findElement(By.xpath("//input[@name='password']"));wait.until(ExpectedConditions.elementToBeClickable(password));

  • 0

    这是一个工作

    driver.manage().window().maximize();
        driver.get("https://www.google.com/intl/en-GB/gmail/about/");
        driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
        driver.findElement(By.xpath("//*[@id=\"identifierId\"]")).sendKeys("Pratik.modh24@gmail.com");
        driver.findElement(By.xpath("//*[@id=\"identifierNext\"]/content/span")).click();
        WebElement password = driver.findElement(By.name("password"));
        password.sendKeys("your_password");
    

相关问题