如何通过 Selenium 和 C# 保存通过 SendKeys() 方法发送的字符序列
How to preserve the character sequence sent through SendKeys() method through Selenium and C#
Selenium c# 在我的测试网站的文本框中输入数据时,光标位置设置为中间,输入的数据类似于例如3421 而不是 1234 的正确顺序。
任何人都可以建议如何处理这个问题的好方法吗?
我试过使用 HOME 键按钮,但没有用。
很难预测 字符序列 在没有相关 HTML。
但是,如果 AUT(正在测试的应用程序) 是 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()
方法并最终按如下方式调用 SendKeys()
方法:
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# 在我的测试网站的文本框中输入数据时,光标位置设置为中间,输入的数据类似于例如3421 而不是 1234 的正确顺序。
任何人都可以建议如何处理这个问题的好方法吗?
我试过使用 HOME 键按钮,但没有用。
很难预测 字符序列 在没有相关 HTML。
但是,如果 AUT(正在测试的应用程序) 是 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()
方法并最终按如下方式调用 SendKeys()
方法:
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");