【发布时间】:2015-10-28 17:22:04
【问题描述】:
我目前正在编写针对电子商务网站的测试。当用户搜索特定产品时,将返回项目列表。我希望做的是将一个特定的值(例如数字 2)传递到我的测试场景中,此时可以将其传递到我的 XPath 表达式(第 n 个子项)中,从而使项目能够被选中。
XPath 不正确,不知道如何修复它。如果有人可以提供帮助将不胜感激。
[Then(@"I select item '(.*)' from the search results")]
public static void WaitAndSelectAnItem(int item)
{
{
Driver.Instance.FindElements(By.CssSelector("#productGrid"));
var itemToSelect = Driver.Instance.FindElement(By.XPath(string.Format("//@class='itemContainer:nth-child({0})'", item)));
itemToSelect.Click();
}
}
结果消息:给定的选择器 //@class='itemContainer:nth-child(3)' 无效或不会生成 WebElement。发生以下错误: InvalidSelectorError: Unable to locate an element with the xpath expression //@class='itemContainer:nth-child(3)' 因为以下错误: TypeError:无法将表达式转换为返回指定的类型。
【问题讨论】:
标签: c# xpath selenium-webdriver