如何通过Selenium和C#保存通过SendKeys()方法发送的字符序列

How to preserve the character sequence sent through SendKeys() method through Selenium and C#(如何通过Selenium和C#保存通过SendKeys()方法发送的字符序列)
本文介绍了如何通过Selenium和C#保存通过SendKeys()方法发送的字符序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium c# 在我的测试网站的文本框中输入数据时,光标位置设置为中间,输入的数据类似于例如3421 而不是 1234 的正确顺序.

Selenium c# when entering data in a Textbox for My Test Website the the cursor position is set to the Middle and the data entered is like for e.g. 3421 instead of the correct Order of 1234.

任何人都可以提出一个如何处理这个问题的好方法吗?

Can anyone suggest a good way as to how to handle this?

我曾尝试使用按 HOME 键按钮,但没有成功.

I have tried to Use pressing the HOME key button but it did not work.

推荐答案

通过发送的字符序列的顺序不持久性背后的实际问题很难预测SendKeys() 方法在没有相关 HTML 的情况下.

It would be tough to predict the actual issue behind the non perseverance of the sequential order of the character sequence sent through SendKeys() method in absence of the relevant HTML.

但是,如果 AUT(被测应用程序) 是 JavaScript, Angular 或 ReactJS基于 ,根据 最佳实践,您需要诱导 WebDriverWait 以使所需的 元素可点击,然后您需要调用 Clear() 方法,最后调用 SendKeys() 方法如下:

However, in case the AUT (Application Under Test) is JavaScript, Angular or ReactJS based, as per best practices you need to induce WebDriverWait for the desired element to be clickable, then you need to invoke Clear() method and finally invoke SendKeys() method as follows:

  • C#:

IWebElement textBoxElement = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("xpath_of_HOME_key_button")));
textBoxElement.Click();
textBoxElement.Clear();
textBoxElement.SendKeys("1234");

这篇关于如何通过Selenium和C#保存通过SendKeys()方法发送的字符序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!
NDK

相关文档推荐

Programmatically show the desktop(以编程方式显示桌面)
How to press the Windows key programmatically using C# SendKeys(如何使用C#SendKeys以编程方式按Windows键)
How to close a permanent element obscuring other elements?(如何关闭永久元素以遮挡其他元素?)
how to send key from my program to external program - winCE(如何将密钥从我的程序发送到外部程序-WinCE)
C# sendkeys to other application to particular textfield(C# 将密钥发送到其他应用程序到特定的文本字段)
Send special character with SendKeys(使用 SendKeys 发送特殊字符)