在以下凭据页面中输入文本时遇到困难: Pixiv
<div class="input-field-group">
<div class="input-field">
<input placeholder="E-mail address / pixiv ID" autocapitalize="off" value="" type="text">
</div>
<div class="input-field">
<input placeholder="Password" autocapitalize="off" value="" type="password">
</div>
</div>
我使用以下代码选择字段,因为 id 属性不可用:
driver.findElement(By.xpath("//input[@placeholder='Password']"));
但我无法通过 sendKeys 或清除操作该元素。 它分别抛出以下异常:
org.openqa.selenium.ElementNotInteractableException: Element is not visible
org.openqa.selenium.InvalidElementStateException: Element is not currently interactable and may not be manipulated
最佳答案
此页面上实际上有两个元素使用该 XPath。 Webdriver 将选择满足开发人员设置的要求的第一个元素。不幸的是,您想要的元素是 DOM 中的第二个元素。然而,更新您的 XPath 使其更加具体将会有所帮助:
driver.findElement(By.xpath("//div[@id='container-login']//input[@placeholder='Password']"));
关于java - 通过占位符选择输入字段 - 元素不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45311044/