XPath的硒发送密钥不起作用

时间:2018-06-20 07:54:23

标签: selenium xpath webdriver sendkeys

我想为此web site自动化 在此网站上的3个文本框中,在此处检查图像

第一个文本框x路径为/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]

这是我的代码

driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");

运行此代码时,我收到此错误

  

线程“主”中的异常   org.openqa.selenium.ElementNotInteractableException:元素无法通过键盘访问

我该如何解决?我希望我的xpath是正确的。

enter image description here

2 个答案:

答案 0 :(得分:0)

该字段具有aria-hidden=true属性,因此您得到ElementNotInteractableException。您需要先单击下拉列表,才能将属性更改为true

WebElement dropdown = driver.findElement(By.xpath("//*[@id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(@class, 'ui-select-search')]"));
textField.sendKeys("rio salon");

答案 1 :(得分:0)

您可以单击带有divspan标签的输入字段,但是不能在该字段中键入。因此,如果要input或在输入字段中键入,则必须使用sendkeys标记编写XPath。例如:

//input[contains(@placeholder,'Site')]