简体   繁体   English

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

[英]How to preserve the character sequence sent through SendKeys() method through Selenium and C#

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 eg 3421 instead of the correct Order of 1234 . Selenium c# 在我的测试网站的文本框中输入数据时,光标位置设置为中间,输入的数据类似于例如3421而不是正确的 Order 1234

Can anyone suggest a good way as to how to handle this?任何人都可以提出一个关于如何处理这个问题的好方法吗?

I have tried to Use pressing the HOME key button but it did not work.我曾尝试使用按 HOME 键按钮,但没有用。

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 .在没有相关HTML 的情况下,很难预测通过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:但是,如果AUT(测试中的应用程序)是基于JavaScriptAngularReactJS的,根据最佳实践,您需要引入WebDriverWait以使所需元素可点击,然后您需要调用Clear()方法并最终调用SendKeys()方法如下:

  • C#: 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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM