我已经在我的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);
}
答案 0 :(得分: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);
答案 1 :(得分: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]
答案 2 :(得分:0)
我需要为每个角色提供一个循环,并且还因为我的计算机是64位而将我的IED驱动程序从32位更新为64位。
示例:
var towncity = _driver.FindElement(PaymentDetailsResponsiveElements.AddressTownCityField);
var towncitytext = "LEEDS";
foreach (char c in towncitytext)
{
towncity.SendKeys(c.ToString());
}