How to Fix Double Characters in Selenium and IE 11 - selenium

When I send "Test" to a textbox the web page displays TTeesstt in the texbox.
Even though the web form displays the double characters it appears what is actually submitted to the web app is only the original text.
When I ran my test using IE 8 the text "Test" was inserted once.
When I upgraded to IE 11 the text was inserted very slowly. This problem was discussed here.
I was trying to solve the slow Sendkeys problem and was playing around with my code to programmatically use IE or Chrome. I've backed off that code to just trying to use IE directly (InternetExplorerDriver class).
I've downloaded and installed all IE 11 cumulative updates.
I saw a post in Kaspersky labs forums about the double character problem. The posts seemed to indicate the problem is related to IBM Trusteer. I do have Trusteer installed on my personal laptop. However, the problem is occurring on a remote computer. I login to the remote computer via a VPN. While not 100% sure I don't think the remote computer has Trusteer.
Environment:
Windows 7 64-bit
InternetDriverServer 3.8.0.0, 32-bit
IE 11.9600.1886IS, Updates KB4052978
Selenium

I had this problem also. I was able to fix it by adding an option to my IEDriver in my selenium code. The option to add is:
ieOptions.EnableNativeEvents = true;
Unfortunately, that slowed my text-entry to about 1 character every five seconds. I was able to fix that by adding RequireWindowFocus = true.
My constructor now contains this code:
if (DriverType.IsType<InternetExplorerDriver>())
{
var ieOptions = new InternetExplorerOptions { IgnoreZoomLevel = true,
EnableNativeEvents = true, RequireWindowFocus = true};
Driver = new InternetExplorerDriver(ieOptions);`
}

For those who has Selenium-Serenity
Thanks to Joshua I found solution to add in serenity.properties
serenity.driver.capabilities=nativeEvents:true;requireWindowFocus:true;

Related

getWindowHandles method returns incorrect number of window handles using MS EDGE IE11 and Selenium version 4.1.2

Recently, I have upgraded my Selenium version from 2.53 to 4.1.2 to enable testing of our application on MS EDGE IE11. But we are intermittently facing issues while retrieving number of windows open in MS EDGE IE11 with selenium-4.1.2
Did anyone else facing similar kind of issues with Selenium-4.1.2 ?
Below is piece of code I have tried on MS EDGE IE11. Sometimes we could see its returning correct no. of windows but sometime not. We are also using sufficient wait-time before retrieving number of windows.
Note - This is working absolutely fine on IE11 browser with Selenium-4.1.2
int noOfWindowsOpen = driver.getWindowHandles().size();
Expectation : It should always return correct value of no. of windows open.
Once you open the new tab / window before you count the number of WindowHandles you need to induce WebDriverWait for numberOfWindowsToBe() as follows:
driver.get("http://www.google.com");
((JavascriptExecutor) driver).executeScript("window.open('http://facebook.com/');");
new WebDriverWait(driver, 10).until(ExpectedConditions.numberOfWindowsToBe(2));
int noOfWindowsOpen = driver.getWindowHandles().size();
It seems to be a known limitation in automating Edge IE mode. It says:
To ensure the new window has been created successfully and IEDriver
has detected it, you must continuously check the result of the Get
Window Handles command until it contains a handle to the new window.
You can try the sample code in it:
int initialHandleCount = driver.getWindowHandles().size();
driver.findElement(By.id("<Id of the button that will open a new window>")).click();
Set<string> newHandles = driver.getWindowHandles();
while (newHandles.size() == initialHandleCount) {
newHandles = driver.getWindowHandles();
}
I have found a work-around for above problem.
Before executing, make sure all the instances of ME Edge, IE and IE Driver are closed. If not, kill them forcefully from task manager and then re-run the Test Script. Script will identify the new window properly.
Thanks

Sending automated text messages from web.skype.com, using Selenium

I’m trying to send automated text messages from Skype web client, using Selenium.
So far, I was able to authenticate myself and select the required unique recipient. It works fine both programmatically (Java bindings) and using Selenium IDE.
But I was not able to successfully add text to the message box. And without that, Skype does not even shows the send button!
In a recent past, I googled that one could send a message with something like:
input_messages = browser.find_element_by_name('messageInput')
input_messages.send_keys('Testing Output' + Keys.RETURN)
But I guess Microsoft changed the web client as this does not work anymore, namely by not showing the “Send” button unless something is written in the message box:
Using Selenium IDE, it records this set of commands (Skype authentication omitted):
However, running above script, I get what seems to be an overlapped “Test” string on top of original “Type a message”:
It seems obvious to me that Selenium IDE is not placing my “Test” string in the “right” place. And because of that, not even the send button is shown.
Here’s the “edit content” parameters:
Target
css=.notranslate
xpath=//div[2]/div[2]/div/div/div/div/div/div/div/div[2]/div/div/div/div[2]/div/div/div
Value
<div data-contents="true"><div class="" data-block="true" data-editor="f244q" data-offset-key="0-0-0"><div data-offset-key="0-0-0" class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"><span data-offset-key="0-0-0"><span data-text="true">Test</span></span></div></div></div>
And the Chrome Inspect of the message box:
So, any idea what Selenium IDE (or myself…) is doing wrong?...
What is the right locator and how to edit its content (to set my text message), making sure the send button is then shown and clickable (though a Keys.ENTER should then suffice).
Thank you in advance!
Windows 10 - 1903 (64-bit)
Google Chrome 85.0.4183.102 (Official Build) (64-bit)
Selenium IDE 3.17.0
chromedriver_win32-85.0.4183.87
selenium-server-standalone-3.141.59.jar
I have encountered similar problems and tried many methods:
clear the element before sendkeys
sendkeys multiple times in for-loop
I can’t tell which method is effective, so I will give you a code snippet in my real project.
// for the div element
boolean bl = false;
for (int i = 0; i < 3; i++) {
element.clear();
element.sendKeys(text);
if (element.getText().equals(text)) {
bl = true;
break;
}
}

IE11 Windows 7 Print issue after kb4021558

Apologies for the slightly vague question but I'm pulling my hair out. Since this update we have had numerous calls regarding printing from our web app. Our web app uses an iframe and we use css #media print to hide all but this iframe for printing purposes. Since the update the user receives an Error 404--Not Found instead of the actual page. It would seem from the network trace that IE creates a temp .htm file in the local directory like D3CD911.htm, it then downloads css/js resources and then finally it makes this call /D3CD911.htm. This is making a call to www.mywebsite.co.uk/D3CD911.htm. This obviously does not exist on the website so the 404 is returned.
I struggling to find a pattern to the problem and it doesn't seem to be affecting other public sites. I think the issue is with window.print() method. I can semi reproduce it here at https://www.primefaces.org/showcase/ui/misc/printer.xhtml. If you click the print button you will get the error. Although this is using the jqprint javascript function if you then use the browser print button it also fails.
Any guidance would be much appreciated.
andyfinch, you're a genius! The following code appears to work for a print button contained within a frame:
function Print() {
if (document.queryCommandSupported('print')) {
document.execCommand('print', false, null);
}
else {
window.parent.<framename>.focus();
window.print();
}
}
Update:
Microsoft have now released a patch: Microsoft IE patch
Just wanted to summarise the workarounds I've found and which have been posted here.
1) If you are using your own print button change to use document.execCommand('print', false, null);. Test support using document.queryCommandSupported('print') and call window.print() if not supported (Prob just Firefox)
2) Use Print Preview. Additionally select the part of the page to print, right click and select print preview. Then select As selected on screen.
3) Use another browser like Chrome
4) Uninstall the update
5) Wait for Microsoft fix. Their KB page KB Link has been updated with this as a known issue. Therefore you assume a fix is on the way.
andyfinch's workaround is also working for us. Thanks Andy!
MS has flagged this issue with "WON'T FIX" (6/15/17): https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12349663/ Update: that flag might just indicate that it's not an issue with MS Edge so it won't get fixed by the Edge developers.
Installing KB4021558 breaks printing from our website (the pages are blank, the footer shows some variant of "res://ieframe.dll/i273gyew.htm"). Uninstalling it restores printing functionality.
KB4021558 is also included in KB4022719, KB4022725 and KB4022727.
I found a workaround: if the iframe you're trying to print is visible, right click on it and choose Print preview... instead of Print... from the context menu. The preview seems to be printable (but may show only part of the frame contents).
Also, for the record, the problematic 64-bit Win7 update is KB4022719.
MS released updates yesterday (June 27th) that address it for Windows 10:
This non-security update includes quality improvements. No new
operating system features are being introduced in this update. Key
changes include:
• Addressed an issue introduced by KB4022715 where Internet Explorer
and Microsoft Edge printing from a frame may result in 404 not found
or blank page printed.
Links:
Windows 10 (Initial Release - Build 10240)
KB4032695 - Build 10240.17446
Windows 10 Version 1511 (Initial Release - Build 10586)
KB4032693- Build 10586.965
Windows 10 Version 1607 (Initial Release - Build 14393)
KB4022723 - Build 14393.1378
Windows 10 Version 1703 (Initial Release - Build 15063)
KB4022716 - Build 15063.447
Source/More info
I grabbed them from the Windows Update Catalog today, to use with WSUS.
Heres the workaround I have been using for this in IE 11:
Right click frame and choose select all, or [ctrl + A] in the frame
Right click and choose print preview
There should be an option in your preview for "As selected on screen". Choosing this allowed me to print everything in the frame.
We were having multiple frames in the print screen and calling document.execCommand('print', false, null); could not fix our issue. Instead window.parent[frameName].document.execCommand('print', false, null); fixed it.

SendKeys on selenium webdriver once in a while sends text in upper case in Internet Explorer 10

SendKeys on selenium webdriver once in a while sends text in upper case in Internet Explorer 10 - for example a login page:
var wait = WebDriverWaitObject();
wait.Until(d => this.driver.FindElement(By.Id("uid")));
this.driver.FindElement(By.Id("uid")).Clear();
this.driver.FindElement(By.Id("uid")).SendKeys(username);
This happens sporadically on IE only and no other browser. Is there a bug with send keys?
Wouldn't be surprised if it was a bug. I'd suggest changing your IE version from 64 bit -> 32 bit or vice versa to test.
Also if you're on 10.0.11 (November 12, 2013) try an older build. For example when I use an older build of chrome sometimes it resolves these kind of issues until the selenium community sends a fix for that browser version.
Lastly, if you're using random generated usernames. Try using a downcase / lower method on the username before sending it to keys. Something like
random_username = "John"
lowercase_username = random_username.lower()
then inject lowercase_username into your selenium code
this.driver.FindElement(By.Id("uid")).SendKeys(lowercase_username)

Selenium: Can't SendKeys() to an item that was below the visible window but was made visible by Click()

I have this problem with a text field that is visible at the time of the SendKeys. I'm using IEDriverServer.exe and C#.
Here's how I can reproduce the problem:
The text field in question is visible in the window but you have to scroll down to see it. To scroll down I click on the element using code like this:
var element = driver.FindElement(By.Xpath("…"));
element.Click();
This scrolls the window down and makes the text field visible.
But when I try to send text to now-visible window:
element.SendKeys("blah");
I get the exception:
When_applicant_enters_application.Should_be_instantly_approved_on_external threw exception: OpenQA.Selenium.ElementNotVisibleException: Element is not displayed
How can I fix or workaround this problem?
Selenium version: 2.32.1
OS: Windows 7
Browser: IE
Browser version: 9.0.15
I've written code demonstrating the problem and submitted it to the Selenium tech support volunteers.
The full discussion is at http://code.google.com/p/selenium/issues/detail?id=5620
but the take-home is:
// Doesn't work
// driver = new InternetExplorerDriver();
// driver.Navigate().GoToUrl(#"D:\CGY\selenium\Bug5620\Bug5620\Bug5620.htm");
// Works
// driver = new FirefoxDriver();
// driver.Navigate().GoToUrl(#"D:\CGY\selenium\Bug5620\Bug5620\Bug5620.htm");
// Works
driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(#"http://localhost:8080/Bug5620/"); // Hosted on Tomcat
so there may be a problem that possibly involves IE, IE security settings, Visual Studio local servers and/or the IE Driver. This may not even be a code problem, but something that needs to be documented, since other people are apparently running into the problem.
I don't know where the problem is exactly but I do have a work-around at this point, which is to use the Firefox Driver.
Thanks for your help, Jim. If you find out a better way of dealing with the problem, please add an answer here for the other folks.