2017-07-25 125 views
0

有一個很難將文本輸入憑據頁: 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

居然有此頁面上有兩個元素使用XPath的。 webdriver將選擇符合開發人員設置要求的第一個元素。不幸的是,你想要的元素是DOM中的第二個元素。但是更新XPath以獲得更具體的信息將有所幫助:

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