Batting: element search in children

I want to do a “two-step” search with Watin. For example, I would like to search for ul-tag with class "abc". Then I would like to find the specific li element 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 on how to do this with Watin?

+4
source share
3 answers

Watin authors told me that this will be supported in a future version. At the moment, this can be done using a filter and lambda.

+2
source

UPDATE

Actually, I just saw information that there is now ie.ElementWithTag, look at this question.
So maybe the rest of this post will not be so helpful.


You do not have a ready-made solution, but perhaps a starting point.
For some (long) time I wrote a script automation for one page. I used powershell, but it is easy to port it to C # (which I assume you are using).

So, in this part of the script, I'm looking for a page element that has a tag input and is called 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 replace the part in loop that is looking for the element’s Save Changes property (and remove the getProperty declaration) with the correct class, than this should do the trick.

+1
source

Implemented in the new version 2.0.50.11579.

Watin 2.0.50.11579

0
source

All Articles