OpenQA.Selenium.NoSuchElementException inside Lambda Expression C# -


i debugging project , have been getting nosuchelementexceptions "unable find element id == txtuserid" while debugging. problem code using lambda expressions return object difficult catch nosuchelementexceptions because makes object out of scope rest of method.

try {    var wait = new webdriverwait(driver, timespan.fromseconds(10));    var itxtuserid = wait.until(d => d.findelement(by.id("txtuserid")));     //clear textbox 'userid' fill user id    itxtuserid.clear();    itxtuserid.sendkeys("userid"); } catch (exception exception) {    // have code here handle exceptions } 

i have read http://watirmelon.com/2014/01/23/checking-an-element-is-present-in-c-webdriver/ suggests writing global variables helper methods prevent these types of errors occuring in first place. however, have heard many developers frown upon use of global variables , can cause problems. feel still necessary able handle exceptions program can on track during runtime. therefore how handle exceptions within lambda expressions? there way return object without lambda expression? statements these throughout code base , examples selenium documentation throw exceptions.

here stack trace "unable find element id == txtsearchbylastname"

var wait = new webdriverwait(driver, timespan.fromseconds(1)); var textusersearch = wait.until(d => d.findelement(by.id(strelementid)));  @ openqa.selenium.remote.remotewebdriver.unpackandthrowonerror(response errorresponse) @ openqa.selenium.remote.remotewebdriver.execute(string drivercommandtoexecutedictionary`2 parameters) @ openqa.selenium.remote.remotewebdriver.findelement(string mechanism, string value) @ openqa.selenium.remote.remotewebdriver.findelementbyid(string id) @ openqa.selenium.by.<>c__displayclass2.<id>b__0(isearchcontext context) @ openqa.selenium.by.findelement(isearchcontext context) @ openqa.selenium.remote.remotewebdriver.findelement(by by) @ automation_solution.navigate.<>c__displayclassc.<patientsearch>b__b(iwebdriver d) in c:\users\username\source\workspaces\testsuite\solution\solution\navigation.cs:line 226    @ openqa.selenium.support.ui.defaultwait`1.until[tresult](func`2 condition) 

it sounds you've got "break on thrown exceptions" set in project. in visual studio, select exceptions... debug menu. in exceptions dialog, make sure check box under "thrown" unchecked.

exceptions dialog screenshot


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -