'ElementNotInteractableException: When sending Arrow Up to a number input with Selenium in Java

I'm inputting a salary in to a tax calculator website but it requires an arrow_up or arrow_down to be sent for it to actually calculate the tax amounts (in lieu of the enter key). I've read online that I ought to be able to send keys.ARROW_UP or keys.ARROW_DOWN but this results in

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'salaryDataLoader': Invocation of init method failed; nested exception is org.openqa.selenium.ElementNotInteractableException: element not interactable

The relevant code is as follows:

        //Works fine and inputs salary number
        WebDriverManager.chromedriver().setup();
        ChromeDriver driver = new ChromeDriver();
        String taxSiteUrl = "https://www.icalculator.info/estonia.html";
        driver.get(taxSiteUrl);
        WebElement salaryInput = driver.findElement(By.id("j2"));  number
        JavascriptExecutor jExec = (JavascriptExecutor) driver;
        String executionScript = String.format("arguments[0].value='%s';", "25000");
        jExec.executeScript(executionScript, salaryInput);

        //Attempt to force calculations by hitting up and then down arrow on number input
        salaryInput.sendKeys(Keys.ARROW_UP);
        salaryInput.sendKeys(Keys.ARROW_DOWN);
        String taxPayableXPath = "//*[@id=\"taxResults\"]/table[1]/tbody/tr[4]/td[1]";
        double taxPayable = Double.parseDouble(driver.findElement(By.xpath(taxPayableXPath)).getText());
       

The input I am targeting is

<input type="number" id="j2" name="j2" value="80000" min="0" step="0.01">


Solution 1:[1]

You can use Implicit wait : driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

And Explicit wait : WebDriverWait wait=new WebDriverWait(driver, 20); element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(taxPayableXPath)));

code:

//Works fine and inputs salary number
        WebDriverManager.chromedriver().setup();
        ChromeDriver driver = new ChromeDriver();
        String taxSiteUrl = "https://www.icalculator.info/estonia.html";
        driver.get(taxSiteUrl);
        WebElement salaryInput = driver.findElement(By.id("j2"));  number
        JavascriptExecutor jExec = (JavascriptExecutor) driver;
        String executionScript = String.format("arguments[0].value='%s';", "25000");
        jExec.executeScript(executionScript, salaryInput);

WebDriverWait wait=new WebDriverWait(driver, 20); element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(taxPayableXPath)));

        //Attempt to force calculations by hitting up and then down arrow on number input
        salaryInput.sendKeys(Keys.ARROW_UP);
        salaryInput.sendKeys(Keys.ARROW_DOWN);
        String taxPayableXPath = "//*[@id=\"taxResults\"]/table[1]/tbody/tr[4]/td[1]";
        double taxPayable = Double.parseDouble(driver.findElement(By.xpath(taxPayableXPath)).getText());
       


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Software Tester at ExpandCart