views:

584

answers:

2

I want to do a "two step" search using Watin. For example I would like to search for a ul-tag having class "abc". Then I would like to search for a certain li-tag inside that element. The code might look like this:

ie.ElementWithTag("ul", Find.ByClass("abc")).ElementsWithTag("li", Find.ByXYZ());

But Element does not have an ElementWithTag method. Any hint how to do that with Watin?

A: 

Hey.


UPDATE

Actually I just saw info that there is ie.ElementWithTag now, look at this question.
So maybe rest of this post won't be that helpful


Don't have ready solution for you, but maybe a starting point.
Some (long) time ago I was writing some automation script for one page. I used powershell but it should be easy to migrate to C# (which I assume you use).

So in this part of script I' searching on page element that has tag input and is named Save Changes.

    #getting property from com object::IHTMLDOMAttribute
    function getProperty ([System.__ComObject] $obj, [string] $prop)
    {
        [System.__ComObject].InvokeMember($prop, [System.Reflection.BindingFlags]::GetProperty, $null, $obj, $null)
    }



    $ie = new-object -com "InternetExplorer.Application";


    $ie.visible = $true;
    $ie.navigate("http://mytestpage.com");
    $doc = $ie.Document;

 $saveButton = $null;
 $inputElts = $null;
 $inputElts = $doc.getElementsByTagName('input')
 foreach ($elt in $inputElts)
 {
     $a = $elt.getAttributeNode('value')
  if ($a -and (getProperty $a 'nodeValue') -eq 'Save changes')
     {
         $saveButton = $elt;
   break;
     }
 }  

So If you would replace part in loop that looks for Save Changes property of element (and delete getProperty declaration) with check for proper class than it should do the trick.

yoosiba
A: 

The authors of Watin told me that this will be supported in the next version. At the moment this can be done using filter and lambdas.

Achim