Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何检查按钮是否被选中_Java_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

Java 如何检查按钮是否被选中

Java 如何检查按钮是否被选中,java,selenium,selenium-webdriver,webdriver,Java,Selenium,Selenium Webdriver,Webdriver,我必须检查是否选择了css按钮 它有两种状态Off=“客户未超过18岁”,On=“客户已超过18岁”由css驱动 我在尝试捕捉状态时遇到了问题,无法决定脚本是否必须单击它。我怎么检查这个 这是我当前用于单击/关闭的xpath: driver.findElement(By.xpath("//i[contains(@class,'c-option__button i-icon i-icon--plus-18-movie')]")); 而uib tooltip=“客户未满18岁”>是更改的文本 但是

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

它有两种状态Off=“客户未超过18岁”,On=“客户已超过18岁”由css驱动

我在尝试捕捉状态时遇到了问题,无法决定脚本是否必须单击它。我怎么检查这个

这是我当前用于单击/关闭的xpath:

driver.findElement(By.xpath("//i[contains(@class,'c-option__button i-icon i-icon--plus-18-movie')]"));
uib tooltip=“客户未满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>

要在检查客户是否超过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");

是否需要先检查元素是否可见?如果是:

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

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

对不起,DebanjanB,但我在帖子中遗漏了部分代码。。。你的代码很有效,这是我第一次发布的代码。你能简单地更新一下你到底在寻找什么吗?我刚刚发布了一篇新的文章,这篇文章正确地解释了我的问题。谢谢