Finding Button within Button Group Class Using Selenium Webdriver in C# -
my end goal able click yes or no on webpage.
using fire bug can see yes , no buttons reside in class called "btn-group"
<div class="btn-group btn-group-default answer-toggle" aria-label="..." role="group"> <button class="btn ng-pristine ng-valid active btn-secondary ng-touched" btn-radio="true" ng-model="consultation.previoussoundvoid" ng-class="{'btn-secondary': consultation.previoussoundvoid}" type="button"> yes </button> <button class="btn ng-pristine ng-untouched ng-valid" btn-radio="false" ng-model="consultation.previoussoundvoid" ng-class="{'btn-secondary': consultation.previoussoundvoid == false}" type="button"> no </button> </div>
i think find element xpath trying improve selenium skill.
i hoping there way first find "btn-group" class somehow choose yes or no within that.
or able create variables both yes , no options. if do:
var button = driver.instance.findelements(by.classname("btn"));
it returns 21 options. found that:
button[15].text returns "yes" button[16].text returns "no"
instead of having through 21 results , worrying if index changes, can search results text somehow?
the best way identify element using text
, xpath
since not have unique id
//button[.='yes']
desperate use cssselector
?
.btn.ng-pristine.ng-valid.active.btn-secondary.ng-touched
since compound class
you can go nth-child()
css
[role='group']>button:nth-child(1)
whereas 2
let select button text no
Comments
Post a Comment