1
if
条件在try
块不起作用。尝试捕捉块如果条件不工作在硒webdriver C#
即使元素(使用Xpath定义)出现/显示在网页中,脚本执行始终会从try catch
循环中走出。 if
条件失败。
任何帮助将不胜感激。
try
{
string path = "//*@id='form_780_0']/div[2]/div/div[3]/div";
if(driver.FindElement(By.XPath(path)).Displayed)
{
Assert.Fail("Fails");
}
}
catch (Exception)
{
//There is nothing here
}
// Some code here and this is executed after evaluating if condition
// even if element is displayed
异常告诉你什么? –
删除尝试和捕获。让它失败并发布完整的例外 –
@RufusL:我更新了我的问题。执行也不会进入异常路径。在评估条件之后,它会退出try catch循环。 – user8356727