C# 含硒容器试验#
如果元素不存在,我如何在c#中继续硒测试C# 含硒容器试验#,c#,json,selenium,C#,Json,Selenium,如果元素不存在,我如何在c#中继续硒测试 如果selenium元素不在页面上,我想跳过它。当没有元素时,可以使用异常处理来避免测试失败 try { webDriver.FindElement(By.Id(id)); } catch(NoSuchElementException) { } 或者使用数组,因为查找多个元素不会导致异常,所以只需空数组即可 IWebElement[] elements = webDriver.FindElements(By.Id(id)).ToArray();
如果selenium元素不在页面上,我想跳过它。当没有元素时,可以使用异常处理来避免测试失败
try
{
webDriver.FindElement(By.Id(id));
}
catch(NoSuchElementException)
{
}
或者使用数组,因为查找多个元素不会导致异常,所以只需空数组即可
IWebElement[] elements = webDriver.FindElements(By.Id(id)).ToArray();
if (elements.Count() != 0)
{
do what you want
}
当没有元素时,您可以使用异常处理来避免测试失败
try
{
webDriver.FindElement(By.Id(id));
}
catch(NoSuchElementException)
{
}
或者使用数组,因为查找多个元素不会导致异常,所以只需空数组即可
IWebElement[] elements = webDriver.FindElements(By.Id(id)).ToArray();
if (elements.Count() != 0)
{
do what you want
}
我想跳过一个不存在的项目并且不停止测试seleniumWell。。。就是这样。我想跳过一个不存在的项目,不停止测试seleniumWell。。。它做到了。