2

I have a little problem with the sendKeys(). It doesn't work in only one field in my form. when I fill in the fields, the value of my field is not changed and the test passed without error message.

Ps: I tried to send the value +newVariable.getDecimalPlaces() in another field and it works. The problem is only from this field, knowing the XPath is correct because I did click on it.

Anyone to help me, please! Thank you :)

        WebElement decimalPlacesTxtBox = driver.findElement(By.xpath(AreaUtils.XPATH_DECIMAL_PLACES));
        action.doubleClick(decimalPlacesTxtBox).perform();
        decimalPlacesTxtBox.sendKeys("" +newVariable.getDecimalPlaces()); 

**The xpath :** 
    public static final String XPATH_DECIMAL_PLACES     = "//*[@id=\"floatValue\"]";  

Sandeep Kumar
  • 2,397
  • 5
  • 30
  • 37
  • does the field that works have an input type of "number"? – pcalkins Dec 19 '19 at 19:28
  • No the field that works has a type text – Nour Elhouda Benyas Dec 20 '19 at 08:15
  • certain browsers will show a different control for type of number which does not return the cursor position as a normal input would. This can cause some quirks when the webdriver attempts to sendKeys. (I think it'll try to place the cursor after the inputted text... but that will fail) – pcalkins Dec 20 '19 at 18:42

2 Answers2

0
  • Firstly, the tag of element should be "input". Eg:

public static final String XPATH_DECIMAL_PLACES = "//input[@id=\"floatValue\"]";

  • And then, you can try to use this code for sendkeys:
Actions actions = new Actions(driver);
actions.moveToElement(element);
actions.click();
actions.sendKeys(text);
actions.build().perform();
  • If it still doesn't work. Please show me the html of the element or screenshot the inspect of that element
The Sun
  • 503
  • 1
  • 3
  • 13
0

If its a input box, Try setting up the value in input box with JavaScriptExecutor, where [id="floatValue"] is the CSS locator of the input field:

((JavascriptExecutor) driver).executeScript("document.querySelectorAll('[id="floatValue"]')[0].value = \"text you want to enter\"");

In some of the text fields Selenium send keys doesn't seem to work. In my case, I was able to enter the text in the text field with help of JavaScript. Please try the above code and let me know if it works.