问题
EDIT : I've found the solutions to this problem : Solution Below
I've been having a funny problem since I've moved my Selenium Server installation to another machine.
Every since i'm running tests on this new machine, my login tests don't work anymore.
After investigation, I've found out that the password field was populated with an incorrect value (hence the test fail).
I'm trying to do the following :
_passWordTextBox.Clear();
_passWordTextBox.SendKeys("!!ä{dasd$352310!!!\\_XY>èà$£<?^^");
Here is how the field is populated after those lines:
As you can notice, the only character that wasn't correctly sent is the "!" character.
It has always worked on my other machine, and several other suspicious candidates (like $ éà<) are sent correctly.
I've looked in the direction of culture differences between computer running and server executing the tests, but i haven't been able to find something conclusive.
I've tried the following :
Password string ( as defined in code ) :
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
Here is what end up being written inside the filed :
"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\ _ abcdefghijklmnopqrstuvwxyz{|}
identified character that don't work :
!]^`~
I've also tried in other fields in my application ( not passowrd or email validated ) such as a Description field, and i'm having the same result : those few character aren't pushed.
I've tried to see if the command was sent correctly to the selenium server, as it stands out it is
08:05:35.850 DEBUG [ReverseProxyHandler.execute] - To upstream: {"value":["!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~?"]}
It means that the server recieves the command correctly but for some reason de driver or the server doesn't execute properly.
回答1:
Try this:
_passWordTextBox.SendKeys(@"!!ä{dasd$352310!!!\\_XY>èà$£<?^^");
Maybe is for the validates from field.
回答2:
You can try using clipboard:
public static void SendValueFromClipboard(this IWebElement txtField, string value)
{
Clipboard.SetText(value);
txtField.SendKeys(OpenQA.Selenium.Keys.Control + "v");
}
This is written on C#, you will need to rewrite it in language, you are using.
回答3:
After looking into multiple system settings i discovered that both my piloting and executing machine add the same regional settings (Format : French(Switzerland) , Keyboard : French(Switzerland), and I didn't look any further. While fiddling around i discovered this setting :
As it turns out , the Language for non-Unicode programs was set to French(Switzerland) on the machine executing the tests. Changing it to English(UK) resolved the problem.
Probably a bug in chromedriver.
来源:https://stackoverflow.com/questions/54769347/sendkeys-method-ignores-some-characters-when-sending-to-a-text-box