Selenium IEDriver sendkeys类型用分号代替冒号

时间:2019-06-27 18:47:29

标签: selenium internet-explorer sendkeys iedriverserver

我正在使用IEDriver在IE上运行硒代码(使用C#)。有时在键入json字符串时(我的测试需要这样做),它将使用分号而不是冒号。这仅在IE上发生。

当我使用剪贴板粘贴字符串时,它不会用半冒号代替冒号。但是,我们希望同时运行测试,因此使用剪贴板不是线程安全的。

当前,我们只是回读输入的内容,如果出现分号,我们将重新输入。但这需要很长时间,因为众所周知,在IE中键入速度非常慢

            wait.WaitForSendKeysText(Defaults_Textbox, Constants.TEN_SECONDS, rebuiltDefaultsJson);
            //this whole section here is a poor work around for IE..  we should move it into WaitForSendKeys at some point
            int i = 0;
            while (Defaults_Textbox.GetAttribute("value").Contains(";") && !rebuiltDefaultsJson.Contains(";"))
            {
                i++;
                FunctionalUtil.LogMessage("Semicolon Error in defaults box, retrying...");
                DefaultsSelect();
                DefaultsClear();
                wait.WaitForSendKeysText(Defaults_Textbox, Constants.TEN_SECONDS, rebuiltDefaultsJson);
                if (i==3)
                {
                    Assert.Fail("Tried 3 times to type a json block without a semicolon and it didnt work");
                }
            }
            FunctionalUtil.LogMessage("Connection information is entered Successfully");

public void WaitForSendKeysText(IWebElement element, int waitInSeconds, string text)
    {
        if (!string.IsNullOrEmpty(element.GetAttribute("value")))
        {
            element.Clear();
        }

        if(Utilities.useSeleniumGrid == "true" || Utilities.isMobile)
        {
            element.SendKeys(text);
            waitInSeconds = 60;
        }
        else
        {
            // The Clipboard is a shared resource and cannot be accessed safely in a multi-threaded setup
            Thread thread = new Thread(() => Clipboard.SetText(text));
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            element.SendKeys(OpenQA.Selenium.Keys.Control + "v");
        }
        ExplicitWaitForTextToBePresentInValue(element, waitInSeconds, text);
    }

0 个答案:

没有答案