使用SendKeys将“@”特殊字符发送到IE 11

时间:2017-09-06 11:00:07

标签: selenium selenium-webdriver internet-explorer-11 sendkeys selenium-iedriver

我正在尝试使用Internet Explorer 11中的SendKeys方法将特殊字符发送到文本框。我在尝试在其他浏览器中发送特殊字符时没有遇到此问题,但Internet Explorer在发送完全不同的字符时试图发送特殊字符。

大多数特殊字符都可以正常工作(例如!#()$%& /),但像@ {}§这样的字符不起作用,而不是那些字符,就像文本框中写的类似vbnm。这些字母表示与键Alt Gr一起创建特殊符号的键(例如Alt Gr + v = @,Alt Gr + b = {,Alt Gr + n =},Alt Gr + m =§)。

我尝试使用Action对象使用KeyDown方法发送密钥,但是当尝试在其中编写带有“@”的字符串(例如username@mail.com)时,它也不成功,特殊符号被替换为字母'v'(usernamevmail.com)。我也尝试使用等效于'@'符号的ASCII,但我没有使用特殊字符,而是在文本框中放置了'64'文本。

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.");
        }
    }

将“@ {}§~$%&()=”字符串发送到文本框时,我将其作为输出。

Username output when sending "@{}§~$%&()=" string to the textbox

1 个答案:

答案 0 :(得分:0)

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