Mark H
Mark H

Reputation: 91

Check if a css button is selected or not

I Have to check if a css button is selected, or not.

If it is on then :

uib-tooltip="The Customer is NOT over 18">

If it is off then :

uib-tooltip="The Customer is over 18">

Too decide if my script has to click on it or not. How do i check this ?.

This is the xpath i am using to currently click it / off on :

driver.findElement(By.xpath("//i[contains(@class,'c-option__button i-icon i-icon--plus-18-movie')]"));

But need a check before it, whether i need to click or not.

<age-question-button class="ng-scope ng-isolate-scope" state="qc.answer[question.name]" icon="plus-18-movie" active-text="The Customer is over 18" inactive-text="The Customer is NOT over 18" ng-repeat="question in qc.questionsList track by question.name" audit="cc.utils.audit(qc.answer[question.name] ? question.auditInactive : question.auditActive)">
<label class="c-option u-p-0 u-ml-md u-pull-left" tooltip-append-to-body="true" uib-tooltip="The Customer is over 18">
<input class="ng-untouched ng-valid ng-dirty ng-valid-parse" ng-model="state" ng-change="audit()" style="" type="checkbox">
<i class="c-option__button i-icon i-icon--plus-18-movie"></i>
</label>

<label class="c-option u-p-0 u-ml-md u-pull-left" tooltip-append-to-body="true" uib-tooltip="The Customer is NOT over 18">
<input class="ng-untouched ng-valid ng-dirty ng-valid-parse" ng-model="state" ng-change="audit()" style="" type="checkbox">
<i class="c-option__button i-icon i-icon--plus-18-movie"></i>

Clickable Image button

Upvotes: 1

Views: 271

Answers (1)

Mahmud Riad
Mahmud Riad

Reputation: 1165

You can check like below

 WebElement element =  driver.findElement(By.xpath("//i[contains(@class,'c-option__button i-icon i-icon--plus-18-movie')]"));

 boolean isChecked = element.findElement(By.tagName("input")).isSelected();
 if(isChecked){
    element.click();
 }

Upvotes: 2

Related Questions