如何在没有元素定位器的情况下通过输入字段的形式键入.tab和sendkeys



我正试图用许多类型的输入字段(文本、单选按钮、数字字段等(填写表单页面,但问题是所有字段都是动态的,这使得处理起来很困难。

我想知道是否可以只在每个字段中键入.tab和send.keys,而不指定字段的元素?或者我需要找到一种使用父div的方法,并对它们进行深入搜索,直到找到特定的元素。提前感谢!

以下是到目前为止我在硒C#脚本中的内容:

public void FillOutForm()
{
//this fills out the first text input field: correct
Driver.FindElement(By.XPath("//input[contains(@id,'sa-txt')]")).SendKeys("Timmy");
//tab to next input field
builder.SendKeys(OpenQA.Selenium.Keys.Tab).Build().Perform();
//this actually enters the text on another field in the form and not the second field: incorrect
new Actions(Driver).SendKeys("Jones").Perform();
builder.SendKeys(OpenQA.Selenium.Keys.Tab).Build().Perform();
Utils.Pause(5000);
}

还有UI检查的屏幕截图ImageofUI

使用绝对xpath不是最佳实践。更好的方法是使用css选择器输入[type='text']获取文本字段的集合,并设置一些值。

相关内容

最新更新