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

Java 通过占位符选择输入字段-元素不可见,java,selenium,Java,Selenium,在以下站点的凭据页面中输入文本时遇到困难: 但我无法通过sendKeys或clear操作元素。 它分别抛出以下异常: org.openqa.selenium.ElementNotInteractableException: Element is not visible org.openqa.selenium.InvalidElementStateException: Element is not currently interactable and may not be manipulat

在以下站点的凭据页面中输入文本时遇到困难:

但我无法通过sendKeys或clear操作元素。 它分别抛出以下异常:

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

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

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