Exception 出现异常时,TestNG执行将停止执行找到的NoTouchElement
在Eclipse中运行TestNG testcase,并使用属性(“value”)从Ui获取值 但是在执行时,如果在UI上找不到webelement,我需要取UIvalue=00:00Exception 出现异常时,TestNG执行将停止执行找到的NoTouchElement,exception,Exception,在Eclipse中运行TestNG testcase,并使用属性(“value”)从Ui获取值 但是在执行时,如果在UI上找不到webelement,我需要取UIvalue=00:00 try { UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttr
try {
UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttribute("value");
// UIValue = WebelementforUIvalue;
}
catch (NoSuchElementException e) {
UIValue ="00.00";
}
但是,当找不到webelement时,执行将停止,我不希望由于异常而停止执行
当在UI上找到WebElement时,执行会运行,但它会显示“无此类元素”并停止执行,如果UI上不存在web元素,在这种情况下,需要将值设置为“00:00”
@niharika_neo,这是下面的堆栈跟踪
{code}
Excel支付区间:JRM1
Excel支付区间值:03:40
UI付费桶:[[ChromeDriver:XP上的chrome(0a57a30b08559c4aa0fe4124c5950760)]->id:ctl00\u main content\u AllowanceGridView\u SRow2812\u JRM1]
03:52
失败
Excel薪资桶:VOTPY
Excel支付区间值:02:01
UI付费桶:[[ChromeDriver:XP上的chrome(0a57a30b08559c4aa0fe4124c5950760)]->id:ctl00\u main内容\u AllowanceGridView\u SRow2102\u VOTPY]
03:52
失败
Excel薪资桶:VOTFA
Excel支付区间值:02:00
没有这样的因素
(会话信息:chrome=39.0.2171.71)
(驱动程序信息:chromedriver=2.10.267521,平台=Windows NT 6.1 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息)
命令持续时间或超时:25毫秒
有关此错误的文档,请访问:
构建信息:版本:“2.42.2”,修订版:“6a6995d”,时间:“2014-06-03 17:42:03”
系统信息:主机:'rainmaker2011-5',ip:'192.168.8.70',os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.7.0'
会话ID:0a57a30b08559c4aa0fe4124c5950760
驱动程序信息:org.openqa.selenium.chrome.ChromeDriver
功能[{platform=XP,acceptSslCerts=true,javascriptEnabled=true,browserName=chrome,chrome={userDataDir=C:\Users\LAKSHM~1.PAL\AppData\Local\Temp\scoped\u dir14544\u 10752},rotatable=false,locationContextEnabled=true,version=39.0.2171.71,takesHeapSnapshot=true,cssselector=true,databaseEnabled=false,handlesAlerts=true,browserConnectionEnabled=false,nativeEvents=true,webStorageEnabled=true,applicationCacheEnabled=false,takesScreenshot=true}]
通过:集成测试
{code}因为您捕获的是NoTouchElementException,它不能作为测试停止的原因。您确定该异常没有在其他位置引发,或者不是引发的另一个异常吗?无论如何,如果元素可能存在或不存在,这似乎不是一个理想的测试。请共享stacktrace。