Search code examples
watin

How to access the link of a listitem


I know there is proably an obvious anwser to this question but I'm trying to learn WatiN and can't figure it out my self :(.

My problem is i need to click a ListItem but i can't get it working as I'd like.

HTML:
<ul class="pageNavigation">
<li><a href="/users/dashboard">&#187; Dashboard</a></li>
<li><a href="/users">&#187; Profile</a></li>
<li><a href="/accounts/settings">&#187; Settings</a></li>

What I'm doing:

ListItem list = ie.List(Find.ByClass("pageNavigation")).ListItem(Find.ByIndex(1));
ie.Link(Find.ByText(list.ToString())).Click();

What I would like to be doing: Instead of getting the ListItem text i would like to get the ListItem href.

NOTE: ie.List(Find.ByClass("pageNavigation")).ListItem(Find.ByIndex(1)).Click(); doesn't work it just clicks the list item area and not the actual link.

Thanks for the help.


Solution

  • Perhaps it might help if you try to click the link itself:

    ie.List(Find.ByClass("pageNavigation")).ListItem(Find.ByIndex(1)).Links[0].Click();
    

    OR

    ie.List(Find.ByClass("pageNavigation")).ListItem(Find.ByIndex(1)).Link(Find.Any).Click();