如何检查是否选择了按钮

时间:2017-11-30 09:28:19

标签: java selenium selenium-webdriver webdriver

我必须检查是否选择了css按钮。

它有两个状态Off ="客户不超过18" ,在="客户超过18岁"它由css驱动。

我在尝试捕获状态时遇到问题,以确定我的脚本是否必须单击它。我如何检查这个?

这是我目前用来点击/关闭的xpath:

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">是更改的文字。

但需要检查一下,无论我是否需要点击。

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

2 个答案:

答案 0 :(得分:1)

要检查是否 The Customer is over 18 ,您可以使用此代码块:

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");

答案 1 :(得分:0)

您是否需要先检查元素是否可见?如果是这样的话:

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

根据下面的帖子,您可能应该为问题的第二部分打开一个新问题,因为它最初没有指定