为了练习起见,我正在为irctc网站编写测试用例,在那里我需要从站点位置输入,然后带有该代码的相应站点将显示为引导下拉列表,现在我必须在其中选择一个并单击回车。不幸的是,没有输入/提交按钮用于from和to text字段,请帮助我继续这个测试用例
这是我的代码
IWebElement Fromstn = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-main-page/div/div/div[1]/div[1]/div[1]/app-jp-input/div/form/div[2]/div[1]/div[1]/span/i"));
Thread.Sleep(2000);
Fromstn.SendKeys("MAQ");
Fromstn.Click();
```**OR**
Actions builder=new Actions(驱动程序); Actions hover=builder.MoveToElement(驱动程序.FindElement(By.XPath("//*[@id='原点']"))); hover.Build().Perform();Thread.睡眠(2000);hover.SendKeys("MAQ");hover.Click();
从输入尝试以下css:
p-autocomplete#origin input
要输入,请尝试以下css:
p-autocomplete#destination input
代码:
driver.FindElement(By.CssSelector("p-autocomplete#origin input")).SendKeys("MAQ");
driver.FindElement(By.CssSelector("p-autocomplete#destination input")).SendKeys("some to station");
如果你想做键盘输入,那么可能会将其与sendkey()一起使用:
像这样的东西:
driver.FindElement(By.CssSelector("p-autocomplete#origin input")).SendKeys("MAQ" + Keys.RETURN);
看看这是否有效:-
driver.FindElement(By.XPath("//label[text()='From']/..//input")).SendKeys("MAQ");
//Add a wait time for the drop down value to load
Actions builder = new Actions(driver);
Actions hover = builder.MoveToElement(driver.FindElement(By.XPath(".//ul[@id='pr_id_1_list']/li"))).Click().Perform();
您可以尝试这段代码。对于调试,请参阅快速观察中的Fromstn对象,看看它是否返回了正确的元素。对于调试,您还可以通过“检查元素”看到元素仍然在表单中,并在断点上使用给定的Xpath进行查找。
IWebElement Fromstn = driver.FindElement(By.XPath("//*[@id='divMain']/div/app-main-page/div/div/div[1]/div[1]/div[1]/app-jp-input/div/form/div[2]/div[1]/div[1]/span/i"));
Thread.Sleep(2000); //you can also try by increasing the value for testing say 10 seconds
Fromstn.Clear();
Fromstn.SendKeys("MAQ");
Fromstn.Click();