I have to enter text in a input box in a selenium test in java. I am using below code to do that and it enters the characters but then deletes it:
WebElement depart=webControls.getDriver().findElement(By.id("oneWayFlight_fromLocation"));((JavascriptExecutor) webControls.getDriver()).executeScript("document.getElementById('oneWayFlight_fromLocation').value='JFK'");
OR
((JavascriptExecutor) webControls.getDriver()).executeScript("arguments[0].value='JFK';",depart);
OR
((JavascriptExecutor) webControls.getDriver()).executeScript(String.format("document.getElementById('oneWayFlight_fromLocation').value='JFK';","JFK"));
Here is the text field:
<input id="oneWayFlight_fromLocation" type="text" class="InputText-control hasError hasIcon" name="oneWayFlight_fromLocation" placeholder="From" autocomplete="off" value="">
I following setup:
- Windows 10 64 bit
- IE11 32 bit
- IE DriverServer 32 bit
- Protection mode is off for all
- nativeEvents is false
- REQUIRE_WINDOW_FOCUS is true
- 64 bit process in unchecked in Advance Security