Sending '@' special character with SendKeys to IE 11

坚强是说给别人听的谎言 提交于 2020-01-02 18:06:08

问题


I'm trying to send a special character to a textbox using the SendKeys method in Internet Explorer 11. I didn't have this problem while trying to send special characters in other browsers, but Internet Explorer is sending completely different characters when trying to send special characters.

Most of the specials characters do work (e.g. !#()$%&/) but the characters like @{}§ are not working, and instead of those characters, something like vbnm is written in the textbox. These letters represents the keys with which the special signs are created in combination with the key Alt Gr (e.g. Alt Gr + v = @, Alt Gr + b = {, Alt Gr + n = }, Alt Gr + m = §).

I tried using the Action object to send the keys with KeyDown method, but it was also unsuccessful, when trying to write a string with '@' in it (e.g. username@mail.com) the special sign is replaced with the letter 'v' (usernamevmail.com). I also tried to use the ASCII equivalent of the '@' sign but instead of the special character, I got the '64' text placed in the textbox.

private static string UserName
    {
        get { return Browser.GetSingleElement(Login.txtUserName).GetAttribute("value"); }
        set
        {
            if (value == null) return;
            var domElement = Browser.GetSingleElement(Login.txtUserName);
            Actions action = new Actions(Browser._driver);
            action.MoveToElement(domElement);
            action.Perform();
            domElement.Clear();
            action.KeyDown(Keys.LeftAlt);
            action.Perform();
            action.SendKeys(Keys.NumberPad6);
            action.SendKeys(Keys.NumberPad4);
            action.Perform();
            //action.MoveToElement(Browser.GetSingleElement(Login.txtUserName)).Click().KeyDown(Keys.LeftAlt).SendKeys("64").Perform();
            if (!Browser.SendKeys(Browser.GetSingleElement(Login.txtUserName), "@{}§~$%&()="))
                throw new Exception("Failed to send keys on Login.txtUserName DOM element.");
        }
    }

When sending "@{}§~$%&()=" string to the textbox I get this as an output.


回答1:


string a = "@{}§~$%&()=";
string b = WebUtility.HtmlDecode(a);


来源:https://stackoverflow.com/questions/46073463/sending-special-character-with-sendkeys-to-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!