2017-10-12 33 views
0

我进入了一个特殊的位置与我的硒,其中我想在IE 11编写使用.SendKeys()整个文本的SendKeys()在IE11不键入整个文本

public void FillEmailAddressField() 
     => _driver.FindElement(PaymentDetailsResponsiveElements.EmailAddressField) 
       .SendKeys("[email protected]"); 

我有什么注意到当我运行测试时,它有时会在不同阶段的输入过程中错过字母。有谁知道这一点,什么是解决这个问题的工作,因为这个问题不会发生在我正在测试的另一个浏览器的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); 

    } 

回答

0

这可能是因为几个问题。您需要为webdriver提供Internet Explorer选项。同时确保缩放级别为100%。 你可以添加下面的代码。使用以下设置,我可以成功地在IE11中自动运行。

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

我能问在哪里把这个代码,请。我是否需要设置一个新的公共无效方法并将其放到那里? –

+0

您应该将此InternetExplorerOptions变量传递给驱动程序构造函数 – cezarypiatek

+0

请参阅编辑问题中的放置位置 –

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("[email protected]", 150); 

你必须调整打字速度。 Accroding的记录看起来遵循wikpedia:

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] 
+0

没有帮助,依然得到'2'而不是'@'... – Azimuth

0

我需要提供每个字符的循环,也更新了我的IEDriver从32位到64位,由于我的电脑是64位。

例子:

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

     foreach (char c in towncitytext) 
     { 
      towncity.SendKeys(c.ToString()); 
     }