2017-10-12 91 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()); 
     }