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
4 Answers
Reset to default 3Instead 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.com");
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
版权声明:本文标题:javascript - How to get password input field ID of gmail wiht selenium Webdriver? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744048053a2581902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论