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