Unable to enter text to input type on Webpage using Selenium Java

前端 未结 3 1645
无人及你
无人及你 2021-01-28 16:54

Uploaded my entire webpage on which my test is failing here: https://drive.google.com/file/d/1WHcwpQFi5Cxh1q1MupQEuSPk6CPZs2GC/view?usp=sharing

Below is my Selenium Java

3条回答
  •  长发绾君心
    2021-01-28 17:29

    Instead of invoking sendKeys() to the you need to invoke on the element and ideally to click() on the element you need to use WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

    • cssSelector:

      WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.row div.field-crtestrequest-cr_app_name>label[for='crtestrequest-cr_app_name']")));
      element.click();
      element.clear();
      element.sendKeys("Allocation");
      
    • xpath:

      WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='row']//div[contains(@class, 'field-crtestrequest-cr_app_name')]/label[@for='crtestrequest-cr_app_name']")));
      element.click();
      element.clear();
      element.sendKeys("Allocation");
      

    References

    You can find a couple of relevant discussions on ElementNotInteractableException in:

    • Selenium WebDriver throws Exception in thread “main” org.openqa.selenium.ElementNotInteractableException
    • org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard: while sending text to FirstName field in Facebook

提交回复
热议问题