steveo 0 Posted November 3, 2016 Report Share Posted November 3, 2016 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. Quote Link to post Share on other sites
deliter 203 Posted November 3, 2016 Report Share Posted November 3, 2016 click(<(tagname="a" AND ng-click="setEdit(item)")>,"Left Click","No") Quote Link to post Share on other sites
steveo 0 Posted November 3, 2016 Author Report Share Posted November 3, 2016 (edited) 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 November 3, 2016 by steveo Quote Link to post Share on other sites
pash 504 Posted November 4, 2016 Report Share Posted November 4, 2016 use "element offset"http://wiki.ubotstudio.com/wiki/Element_Offset Quote Link to post Share on other sites
deliter 203 Posted November 4, 2016 Report Share Posted November 4, 2016 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) } } } Quote Link to post Share on other sites
steveo 0 Posted November 4, 2016 Author Report Share Posted November 4, 2016 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. Quote Link to post Share on other sites
deliter 203 Posted November 4, 2016 Report Share Posted November 4, 2016 check out my css selector plugin Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.