通过占位符选择输入字段 - 元素不可见

时间:2017-07-25 18:28:47

标签: java selenium

很难将文字输入到凭据页面上: 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

1 个答案:

答案 0 :(得分:1)

此页面上实际上有两个元素使用该XPath。 webdriver将选择满足开发人员设置要求的第一个元素。不幸的是,你想要的元素是DOM中的第二个元素。但是,将XPath更新为更具体将有助于:

driver.findElement(By.xpath("//div[@id='container-login']//input[@placeholder='Password']")); 
相关问题