Jump to content
UBot Underground

Trouble With Selectors


Recommended Posts

I'm trying to click an edit button in a table and I'm struggling to figure out the ubot way of doing this.  Here is the row from table.

<tr ng-repeat="item in blacklists" class="ng-scope">

	<td class="ng-binding">test black list</td>

	<td class="text-right">
		<a href="#" ng-click="setEdit(item)"><i class="glyphicon glyphicon-pencil"></i></a>
		<a href="#" ng-click="delItem(item)"><i class="glyphicon glyphicon glyphicon-trash"></i></a>
	</td>
</tr>

The element I need to click is this one "<a href="#" ng-click="setEdit(item)">"

 

Seems fairly straightforward.  However I need to click that element in the row that contains "<td class="ng-binding">test black list</td>".  So I somehow need to narrow down my selector for the edit button so it only searches within the <tr> element that contains the text "test black list".

 

Any tips on how to do this?  I'm a coder of 20 years experience so this kind of thing is normally easy to do with xpath and the like.  But I can't figure it out in ubot.

Link to post
Share on other sites

Hi Deliter.  That will work fine if there's only one table row.  But there's two and I only want to click the one that contains the text "test black list".  I should have posted a bit more of the html.  And to clarify, this table could have any number of rows in it and the target row could be in any position so I can use a fixed position or anything like that.  I need to start from "<td class="ng-binding">test black list</td>" which is effectively a unique marker then navigate to the next TD then down to the first A tag.

<tr ng-repeat="item in blacklists" class="ng-scope">

	<td class="ng-binding">DON'T WANT THIS ROW</td>

	<td class="text-right">
		<a href="#" ng-click="setEdit(item)"><i class="glyphicon glyphicon-pencil"></i></a>
		<a href="#" ng-click="delItem(item)"><i class="glyphicon glyphicon glyphicon-trash"></i></a>
	</td>
</tr>

<tr ng-repeat="item in blacklists" class="ng-scope">

	<td class="ng-binding">test black list</td>

	<td class="text-right">
		<a href="#" ng-click="setEdit(item)"><i class="glyphicon glyphicon-pencil"></i></a>
		<a href="#" ng-click="delItem(item)"><i class="glyphicon glyphicon glyphicon-trash"></i></a>
	</td>
</tr>


Edited by steveo
Link to post
Share on other sites

this maybe a bit unnecessary by sometimes I do stuff like this,it just makes things easier if Ubots selectors are not complex enough for the job,Ive added a href of "here" to the code to show that it did click the right button,using pashs suggestion of element offset

 

*would be better to use td and class= ng-binding for eachRow list,with scrape textContent but should still work

load html("<table>

<tr ng-repeat=\"item in blacklists\" class=\"ng-scope\">

	<td class=\"ng-binding\">DON\'T WANT THIS ROW</td>

	<td class=\"text-right\">
		<a href=\"#\" ng-click=\"setEdit(item)\"><i class=\"glyphicon glyphicon-pencil\"></i></a>
		<a href=\"#\" ng-click=\"delItem(item)\"><i class=\"glyphicon glyphicon glyphicon-trash\"></i></a>
	</td>
</tr>

<tr ng-repeat=\"item in blacklists\" class=\"ng-scope\">

	<td class=\"ng-binding\">test black list</td>

	<td class=\"text-right\">
		<a href=\"here\" ng-click=\"setEdit(item)\"><i class=\"glyphicon glyphicon-pencil\"></i></a>
		<a href=\"#\" ng-click=\"delItem(item)\"><i class=\"glyphicon glyphicon glyphicon-trash\"></i></a>
	</td>
</tr>

</table>

")
add list to list(%eachRow,$scrape attribute(<class="ng-scope">,"outerhtml"),"Delete","Global")
set(#position,0,"Global")
loop while($comparison(#position,"<",$list total(%eachRow))) {
    if($contains($list item(%eachRow,#position),"test black list")) {
        then {
            click($element offset(<(tagname="a" AND ng-click="setEdit(item)")>,#position),"Left Click","No")
            set(#position,$list total(%eachRow),"Global")
        }
        else {
            increment(#position)
        }
    }
}

Link to post
Share on other sites

Thanks Deliter.  That did the trick.

 

Before I read your post I'd gone as far as trying to write a plugin with my own selector function but realised the API doesn't have an interface for whatever object type a selector returns.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...