如何通过Selenium和C#保留通过SendKeys()方法发送的字符序列 [英] How to preserve the character sequence sent through SendKeys() method through Selenium and C#

查看:190
本文介绍了如何通过Selenium和C#保留通过SendKeys()方法发送的字符序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

硒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 角度 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#:

  • 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()方法发送的字符序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆