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

前端 未结 3 1646
无人及你
无人及你 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:28

    I think the element which you needed is present on the DOM, but it is not in a state that you can interact with them.

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.ignoring(StaleElementReferenceException.class).until(ExpectedConditions.elementToBeClickable(By.id("crtestrequest-cr_app_name")));
    WebLement input = driver.findElement(By.id("crtestrequest-cr_app_name"))
    input.click();
    input.clear();
    input.sendKeys("123");
    

    or

    for(int i=0; i<=2;i++){
      try{
         WebLement input = driver.findElement(By.id("crtestrequest-cr_app_name"))
         Actions actions = new Actions(driver);
         actions.moveToElement(input).perform();
         input.click();
         break;
       } catch (StaleElementReferenceException e) {
               System.out.println("Trying to recover from a stale element :" + e.getMessage());
       }
    }
    

提交回复
热议问题