How to get password input field ID of gmail wiht s

2019-07-13 03:40发布

The new JS enabled page of http://mail.google.com is making trouble to get ID of password input field. However, I've navigated from email ID page with its ID - identifierID .

Help me to get ID of password field.

Thanks in advance...

4条回答
We Are One
2楼-- · 2019-07-13 04:11

Use a combination input element and the div having Inner text

<div jsname="YRMmle" class="AxOyFc snByac" aria-hidden="true">Enter your password</div> .

Also on clicking the correct element, the parent element changes which makes you to find the element again and send the value.

You can use CssSelector or Xpath to attain this easily. But you Google will definitely be changing this so often.

查看更多
仙女界的扛把子
3楼-- · 2019-07-13 04:19

Please find the updated code:

Code:

    driver.manage().window().maximize();
    driver.get("http://www.gmail.c‌​om"); 
    WebElement elementid = driver.findElement(By.id("identifierId")); 
    elementid.sendKeys(""); 
    WebElement elementnxt = driver.findElement(By.id("identifierNext")); 
    elementnxt.click();
    WebDriverWait wait = new WebDriverWait(driver, 100);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='password']")));
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='password']")));
    WebElement elementpwd = driver.findElement(By.xpath("//input[@type='password']"));
    elementpwd.sendKeys("123");

I have validated it on my end. Let me know if this doesn't work.

查看更多
Viruses.
4楼-- · 2019-07-13 04:26

Instead if Id use name attribute to get access of the field.

document.getElementsByName("password")[0];

It will give you password input element.

<input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" autocorrect="off" dir="ltr" data-initial-dir="ltr" data-initial-value="">
查看更多
狗以群分
5楼-- · 2019-07-13 04:33

Try to set the value of the field using JavaScript

as

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("var elements = document.getElementsByName('password');elements[0].setAttribute('value', '123');");

查看更多
登录 后发表回答