1

我的 selenium 进入了一个特殊的位置,我试图在 IE 11 中使用 .SendKeys() 编写整个文本。

  public void FillEmailAddressField()
        => _driver.FindElement(PaymentDetailsResponsiveElements.EmailAddressField)
                .SendKeys("Test@email.co.uk");

我注意到的是,当我运行测试时,它有时会在不同阶段的打字过程中丢失字母。有谁知道这一点以及解决此问题的方法是什么,因为此问题不会发生在我正在测试的另一个浏览器 chrome 上。

编辑:我不确定,但这就是我放的地方:

public class PaymentDetailsResponsive
{
    private readonly IWebDriver _driver;
    private readonly CharacterGenerator _characterGenerator;
    private readonly InternetExplorerDriver driver;

    public PaymentDetailsResponsive(IWebDriver driver)
    {
        _driver = driver;
        _characterGenerator = new CharacterGenerator();

        var internetExplorerOptions = new InternetExplorerOptions
        {
            RequireWindowFocus = true,
            EnablePersistentHover = true,
            EnableNativeEvents = true,
            IntroduceInstabilityByIgnoringProtectedModeSettings = true,
            IgnoreZoomLevel = true
        };
        this.driver = new InternetExplorerDriver(internetExplorerOptions);

    }
4

3 回答 3

1

这可能是由于几个问题。您需要为 webdriver 提供 Internet Explorer 选项。还要确保缩放级别为 100%。你可以添加下面的代码。我可以通过以下设置成功地在 IE11 中实现自动化。

  var internetExplorerOptions = new InternetExplorerOptions
                {
                    RequireWindowFocus = true,
                    EnablePersistentHover = true,
                    EnableNativeEvents = true,
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                    IgnoreZoomLevel = true
                };
                this.driver = new InternetExplorerDriver(internetExplorerOptions);
于 2017-10-12T14:30:44.407 回答
0

我需要为每个字符提供一个循环,并且由于我的计算机是 64 位,我的 IEDriver 从 32 位更新到了 64 位。

例子:

        var towncity = _driver.FindElement(PaymentDetailsResponsiveElements.AddressTownCityField);
        var towncitytext = "LEEDS";

        foreach (char c in towncitytext)
        {
            towncity.SendKeys(c.ToString());
        }
于 2017-10-13T11:12:14.793 回答
0

我观察到与 ChromeDriver 类似的问题。它输入得太快以至于错过了一些字母(我不知道如何)。所以我引入了 Type 方法来解决这个问题。

/// <summary>
/// Tyoe text into field
/// </summary>
/// <param name="input">Field</param>
/// <param name="text">Text to tyoe</param>
/// <param name="speed">Speed of typing (chars per minute). 0 means default selenium speed</param>
public static void Type(this IWebElement input, string text, int speed = 0)
{
    if (speed == 0)
    {
        input.SendKeys(text);
    }
    else
    {
        var delay = (1000*60)/speed;
        foreach (var charToType in text)
        {
            input.SendKeys(charToType.ToString());
            Thread.Sleep(delay);
        }
    }
}

我用它代替 SendKeys()

public void FillEmailAddressField()
       => _driver.FindElement(PaymentDetailsResponsiveElements.EmailAddressField)
               .Type("Test@email.co.uk", 150); 

你必须调整打字速度。根据维基百科,记录如下:

The fastest typing speed on an alphanumeric keyboard, 216 words in one minute, was achieved by Stella Pajunas in 1946 on an IBM electric.[5][6][7] As of 2005, writer Barbara Blackburn was the fastest alphanumerical English language typist in the world, according to The Guinness Book of World Records. Using the Dvorak Simplified Keyboard, she maintained 150 wpm for 50 minutes, and 170 wpm for shorter periods. Her top speed was 212 wpm. Current online records of sprint speeds on short text selections are 290 wpm, achieved by Guilherme Sandrini on typingzone.com and 295 wpm achieved by Kathy Chiang on TypeRacer.com. For longer passages, Sean Wrona holds the record with 174 wpm on a 50-minute test taken on hi-games.net.[8]
于 2017-10-12T15:00:46.170 回答