2017-11-30 33 views
0

CSSボタンが選択されているかどうかを確認する必要があります。ボタンが選択されているかどうかを確認する方法

オフ= "お客様は18歳以上ではありません"、オン= "お客様は18歳以上です"とは、cssによって駆動されます。

状況を把握しようとすると、スクリプトがクリックしなければならないかどうかを判断する際に問題が発生します。どのように私はこれをチェックするのですか?

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

uib-tooltip="The Customer is NOT over 18">変更したテキストです:

これは私が現在のそれをオン/オフ]をクリックして使用していますxpathがあります。

私はクリックする必要があるかどうかを確認する必要があります。 The Customer is over 18かどうかの前にチェックする

<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> 

答えて

1

、あなたは、このコードブロックを使用することができます。

if(driver.findElement(By.tagName("age-question-button")).getAttribute("active-text").contains("NOT")) 
    System.out.println("The Customer is NOT over 18"); 
else 
    System.out.println("The Customer is over 18"); 
+0

申し訳DebanjanB指定されたが、私は、コードの一部を逃していなかったとして、あなたはおそらくあなたの問題の第二部のための新しい質問を開く必要があります私のポストでは... 最初に投稿したビットのために、コードが動作します。 –

+0

あなたはあなたが探しているものを簡単に更新できますか? – DebanjanB

+0

はちょうど私の質問を正しく説明する新しい投稿をしました。ありがとう。 –

0

あなたは要素が最初に表示されているかどうかを確認する必要がありますか?その場合:以下の記事を1として

driver.findElement(By.id("idOfElement")).isDisplayed(); 

それは元々

関連する問題