admin管理员组

文章数量:1355581

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

How can I get the ID of password field?

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

How can I get the ID of password field?

Share Improve this question edited Dec 9, 2021 at 6:15 cigien 60.5k11 gold badges81 silver badges121 bronze badges asked Jun 24, 2017 at 16:04 VickyVicky 251 gold badge1 silver badge7 bronze badges 1
  • can you paste the HTML? – santhosh kumar Commented Jun 24, 2017 at 16:08
Add a ment  | 

4 Answers 4

Reset to default 3

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" autoplete="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="">

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.

Use a bination 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.

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

本文标签: javascriptHow to get password input field ID of gmail wiht selenium WebdriverStack Overflow