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
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());
}
}
Instead of invoking sendKeys() to the <label>
you need to invoke on the <input>
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");
You can find a couple of relevant discussions on ElementNotInteractableException in:
I have been trying past 24 hours to get this to work and finally did.
Before, I trigger the Search Assests
button as visible in my video @ 1.11 minutes I tried the below code which worked.
WebElement ele = driver.findElement(By.id("crtestrequest-cr_app_code"));
JavascriptExecutor exec = (JavascriptExecutor)driver;
exec.executeScript("arguments[0].click();", ele);
driver.findElement(By.id("crtestrequest-cr_app_code")).clear();
driver.findElement(By.id("crtestrequest-cr_app_code")).sendKeys("Allocation");