elem.innertext

Class library usage, coding and language questions.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

elem.innertext

Post by omayer » Tue Dec 04, 2012 7:51 pm

How to handle when there is no element on /td[3] ,since there is an uncertain delay to get the innertext,
now getting error on- _psld=elem.innertext -- Object reference not set to an instance of an object.
I don't get the error when there is an innertext,

WebElement elem = "/dom[@caption='xxProfile']//div[@id='flashRoot_1']/table[2]/tbody/tr/td[1]/table[1]/tbody/tr[3]/td[1]/table/tbody/tr[10]/td[3]";

_psId = elem.InnerText;

------

here is the full code

public string CopyId()
{

int counter =0;
_psId = " ";
while(_psId ==" ")
{
WebDocument web = "/dom[@caption='xxProfile']";
web.EnsureVisible();
Delay.Ms(20000);
Keyboard.Press("{F5}");
Delay.Ms(20000);

WebElement elem = "/dom[@caption='xxProfile'Profile']//div[@id='flashRoot_1']/table[2]/tbody/tr/td[1]/table[1]/tbody/tr[3]/td[1]/table/tbody/tr[10]/td[3]";

_psId = elem.InnerText.Trim(); //getting Error when there is no innertext-Object reference not set to an instance of an object
counter = counter+1;

if (counter==5)

_psId ="NotFound";
break;
}

}
}
Thank you in Advance
Tipu

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: elem.innertext

Post by Ciege » Tue Dec 04, 2012 7:52 pm

Put a try/catch block in. Catch and deal with the exception if it occurs.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Re: elem.innertext

Post by omayer » Tue Dec 04, 2012 9:08 pm

Thank you Ciege, try catch will work.
Tipu