【问题标题】:Gmail Password- i can not find Xpath in PAssword, Code is write but not right Password [duplicate]Gmail密码-我在PAssword中找不到Xpath,代码是写的,但密码不正确[重复]
【发布时间】:2018-08-30 11:17:57
【问题描述】:
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();

        //Below Code password not print on PAssword textbox
        //driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/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");     
    }
}

【问题讨论】:

    标签: selenium selenium-webdriver xpath


    【解决方案1】:

    这个XPATH应该选择gmail“密码输入”://input[@name='password']

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

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

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

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

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

    【讨论】:

    【解决方案2】:

    这是一个工作

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-13
      • 1970-01-01
      相关资源
      最近更新 更多