Cucumber/Selenium在未找到元素时抛出更详细的错误
当找不到元素时,Selenium/Cucumber是否有方法抛出更具描述性的错误?目前它只抛出: 找不到元素(Selenium::WebDriver::Error::NoSuchElementError)Cucumber/Selenium在未找到元素时抛出更详细的错误,selenium,cucumber,runtime-error,element,Selenium,Cucumber,Runtime Error,Element,当找不到元素时,Selenium/Cucumber是否有方法抛出更具描述性的错误?目前它只抛出: 找不到元素(Selenium::WebDriver::Error::NoSuchElementError) 我还想包括定位器 这取决于测试夹具代码的设计和结构。您可以在try/catch块中包装FindElement代码。比如: Public void TestMethod(string elementId) { try { driver.FindElement(By.CssSele
我还想包括定位器 这取决于测试夹具代码的设计和结构。您可以在try/catch块中包装FindElement代码。比如:
Public void TestMethod(string elementId)
{
try
{
driver.FindElement(By.CssSelector(elementId));
}
catch(NoSuchElementException exception)
{
Assert.Fail("Can't find the element in the page. The element is: " +elementId)
}
}