Update 2
I am working on .Net using C# with the control called GridView… so gridview control renders and spit this html something like this: this is just an one small sample html source one TR I have like 100s of that…
<tr class="item">
<td align="center">
<td align="center" style="width:15px;"/>
<td>John John</td>
<td/>
<td>Friendship</td>
<td/>
<td>
<td>9/7/2012 6:28:29 PM</td>
</tr>
so, I am trying to find if John John exists and here is how i am end-up using the XPATH
int pageCount = 100;
bool assertFlag = false;
for (int i = 0; i < pageCount; i++)
{
try
{
string _Id = String.Format("//*[@id='ctl00_ContentPlaceHolder1_AddeCardControl1_gridview_control']/tbody/tr[{0}]/td[3]", i);
string _txt = GetText(By.XPath(_Id));
if (_txt == "some text comparing here")
{
//matched
assertFlag = true;
break;
}
}
catch (Exception e)
{
//
}
}
What do you think guys? or am I making something horrible terrible wrong?
PS: there is no ID or CSS selector I can do so I have no other options other than using the XPATH
END UPDATE 2
UPDATE
I am using Selenium WebDriver 2 with C# and I am using IE 8 and FF
END UPDATE
I am still not sure what causes this error to be thrown so i have script and it works and when i run the second time it fails and get the below message… and if i keep running more than once then sometimes it works and sometimes not… what should i do? what causes this error? any insight?
sometimes I get this error message:
Element is no longer valid
sometimes this:
Unable to find element with xpath == //*[@id='ctl00_ctl00_ctl00_LeftNavigation_LeftNavigation_LeftNavigationControl1_rptLeftNav_ctl14_lnkText']
I think your last question; Getting Timeout using Selenium Webdriver had a lot of good stuff. That was relevant to the question you’re asking. If you can’t find an element using one type of locator, try another type.
I also couldn’t help but notice you were using an xpath locator for IE. There is a really good webinar of why you should never use xpath in IE (and in general) due to speed issues, this might be causing some of your current issues.
Here is the link: http://sauceio.com/index.php/2011/05/why-css-locators-are-the-way-to-go-vs-xpath/ . The webinar investigates why CSS is superior to xpath especially with IE. CSS aside, the errors you’re getting can be caused by anything though from your box settings to the browser you’re using, web automation is not an exact science after all. Hell you could have a bug as well…isn’t that what you’re testing for in the first place?
EDIT
So your updates are a little strange to me because you totally switched from looking for multiple elements under something with an individual id to looking for an element in a tag. In regard to your current update I would suggest just using the css locator saying
If your tag can’t be found you will doubtless be told. As I mentioned earlier, css locators accomplish the same thing as xpath, but they are faster and work better in IE. Yes they do not work 100% of the time. Maybe for 5 times out of 100 you need to use xpath over css but overall css is superior. Please read the relevant links if you are still unsure of how to utilize them, they are well written and were very helpful for me.