Search code examples
seleniumxpathwebdriversendkeys

selenium send key for xpath not working


I want make automation for this web site in this web site 3 text box are here check image

1st text box x path is /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]

here is my code

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

when I run this code I got this error

Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard

How can i fix it? I hope my xpath is correct.

enter image description here


Solution

  • The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to 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");