我想测试以确保搜索显示正确的结果。
我已经在XPaths和CssSelectors的许多变体中尝试了下面的代码。
IWebElement body = driver.FindElement(By.XPath("//span[@class='CoveoQuerySummary']"));
return (body.Text.Contains(searchTerm)); 我总是得到一个NullReferenceException错误。我正在经历它,所以我知道这不是一个等待的问题。
我已经尝试过这种方法,但没有走得太远。(当我调试时,我得到相同的NullReferenceException错误。)
IList<IWebElement> all = driver.FindElements(By.CssSelector(".CoveoResultList"));
String[] allText = new String[all.Count];
int i = 0;
foreach (IWebElement element in all)
{
allText[i++] = element.Text;
}任何和所有的帮助都将不胜感激!
发布于 2016-12-21 03:56:50
var temp = driver.FindElement(By.ClassName("CoveoQuerySummary"), 10);
IWebElement body = driver.FindElement(By.ClassName("CoveoResultList"));
if (body.Text.Contains(searchtext))
result = true;
Assert.IsTrue(result);上面的代码对我有效(终于!) --我认为我更大的问题是/正在尝试使用(并同时学习)页面对象模型。如果我将上面的'FindElement‘调用放在PageObject文件中,它们总是返回一个NullReferenceException。我还在学习&我知道这可能需要重构--但它是有效的。
任何建议都是非常感谢的!
https://stackoverflow.com/questions/40729653
复制相似问题