Reputation: 389
I'm facing an issue like, SendKeys() is not passing the values to the correct fields even given valid ID in Internet Explorer 11. If I run the same script in the Chrome 66+ browser it works as expected. Why?
Script:
// Address Line1
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_address1_text")).clear();
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_address1_text")).sendKeys(ADDRESS1);
Thread.sleep(1000)
// City
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_city_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_city_text")).sendKeys(CITY_NAME)
Thread.sleep(1000)
// State
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_state_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_state_text")).sendKeys(STATE_CODE)
Thread.sleep(1000)
// Postal code
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_postalCode_text")).clear()
driver.findElement(By.id("accountForm:accountTabSet:0:paCustForm_main_postalCode_text")).sendKeys(POSTAL_CODE)
Thread.sleep(1000)
The script above mentioned taken from Update Screen. So I'm clearing the existing content and passing the values to the respective fields.
Issue: The values are mismatched i.e. AddressLine1 value is passed to City and PostalCode field receiving FirstName value (FYI: I didn't mention in the script)
While executing the same script in Chrome Browser, it works properly. Why?
Anyone pleas give me the solution for this ?
Thanks
Karunagara Pandi
Upvotes: 0
Views: 1713
Reputation: 430
I have IE11 32 bit browser and 32 bit IE Driver Server on Windows 10 64 bit OS.
I can enter the text in edit field using sendkeys but it gets removed after that.
//WebElement depart=webControls.getDriver().findElement(By.id("oneWayFlight_fromLocation")); //((JavascriptExecutor) webControls.getDriver()).executeScript("document.getElementById('oneWayFlight_fromLocation').value='JFK'"); //((JavascriptExecutor) webControls.getDriver()).executeScript("arguments[0].value='JFK';",depart); ((JavascriptExecutor) webControls.getDriver()).executeScript(String.format("document.getElementById('oneWayFlight_fromLocation').value='JFK';","JFK"));
JFK is entered but then deleted:
Upvotes: 0
Reputation: 1481
This issue tends to happen. Can be due wrong driver, wrong version of driver, and the fact IE is actually and disaster of a browser. You are probably finding element correctly (if it works for Chrome) but sendKeys() method is just not working properly for IE it has issues, this issue happens also on Safari.
Try one of this, it might help:
For 64 bit WebDriver: 1. Open IE 2. Go to Internet Options → Advanced → Security 3. Check ☑ Enable 64-bit processes for Enhanced Protected Mode Click 4. Apply and OK
For 32 bit WebDriver: 1. Open IE 2. Go to Internet Options → Advanced → Security 3. Uncheck ☐ Enable 64-bit processes for Enhanced Protected Mode 4. Click Apply and OK
And also:
Internet Options -> Security -> Check "Enable Protected Mode" for all zones Go to Advanced -> Security -> Check "Enable Enhanced Protected Mode"
And in code try this:
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
...
capabilities.setCapability("requireWindowFocus", true);
WebDriver driver = new InternetExplorerDriver(capabilities);
and try this, but for me this worked only on several versions of IE:
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('ID').value='VALUE';");
Upvotes: 3