在Eclipse中运行TestNG测试用例,并使用属性("值")从Ui获取值。
执行时BUT,如果webelement不存在/在UI上找到,我需要取UIvalue = 00:00。
try {
UIValue = driver.findElement(By.id("ctl00_MainContent_AllowanceGridView_SRow"+cellRosterPerioddd+cellRosterPeriodmm+"_"+PayBucket)).getAttribute("value");
// UIValue = WebelementforUIvalue;
}
catch (NoSuchElementException e) {
UIValue ="00.00";
}
但是,当找不到webelement时,执行会停止,我不希望执行停止执行异常?
答案 0 :(得分:0)
@Stijn
当在UI上找到WebElements时,执行会运行,但是如果UI上没有Web元素,则会删除“No such Element”并停止执行,在这种情况下,需要将值取为'00: 00'
@ niharika_neo,这是下面的Stack Trace
Excel PayBucket:JRM1 Excel PayBucket价值:03:40 UI PayBucket:[[ChromeDriver:XP上的chrome(0a57a30b08559c4aa0fe4124c5950760)] - > id:ctl00_MainContent_AllowanceGridView_SRow2812_JRM1] 3时52
Excel PayBucket:VOTPY Excel PayBucket价值:02:01 UI PayBucket:[[ChromeDriver:XP上的chrome(0a57a30b08559c4aa0fe4124c5950760)] - > id:ctl00_MainContent_AllowanceGridView_SRow2102_VOTPY] 3时52
Excel PayBucket:VOTFA Excel PayBucket价值:02:00 没有这样的元素 (会话信息:chrome = 39.0.2171.71) (驱动程序信息:chromedriver = 2.10.267521,platform = Windows NT 6.1 SP1 x86_64)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:25毫秒 有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'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.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_dir14544_10752},rotate = false,locationContextEnabled = true,version = 39.0.2171.71,takesHeapSnapshot = true,cssSelectorsEnabled = true,databaseEnabled = false,handlesAlerts = true,browserConnectionEnabled = false,nativeEvents = true,webStorageEnabled = true,applicationCacheEnabled = false,takesScreenshot = true}] 通过:IntegrationTests
{代码}