c# - How to click on a link with no ID or Name? -


html code:

<a ng-repeat="group in groups()" ng-href="phones/apple/iphone%203g%20or%203gs/" class="ng-scope" href="phones/apple/iphone%203g%20or%203gs/">         <div class="card-box device-box">             <span class="card-text ng-binding">iphone 3g or 3gs</span>             <i class="fa fa-chevron-right visible-xs"></i>             <div class="clearfix"></div>         </div>     </a> 

c# code:

driver.findelement(by.linktext("iphone 3g 16gb")).click(); 

i make xpath expression here find a element has span element inside having iphone 3g or 3gs text:

driver.findelement(by.xpath("//a[div/span = 'iphone 3g or 3gs']")).click(); 

you may try approaching partiallinktext locator instead:

driver.findelement(by.partiallinktext("iphone 3g 16gb")).click(); 

Comments