Selenium Webdriver捕获复选框文本

Selenium Webdriver捕获复选框文本,selenium,selenium-webdriver,checkbox,Selenium,Selenium Webdriver,Checkbox,您好,我正在尝试捕获同一span类中复选框旁边的名称,但名称位于标签标记中。当尝试使用getText()方法捕获文本时,我得到的是空名称 在代码中显示我是如何做的 //to find the checkbox @FindBy(how = How.ID, id = "ConstructionManagement") private WebElement constructionMgmnt; 当使用这个getText时,我得到的是空文本。使用getAttribute时,我得到的复选框的实际名称是$

您好,我正在尝试捕获同一span类中复选框旁边的名称,但名称位于标签标记中。当尝试使用getText()方法捕获文本时,我得到的是空名称

在代码中显示我是如何做的

//to find the checkbox
@FindBy(how = How.ID, id = "ConstructionManagement")
private WebElement constructionMgmnt;
当使用这个getText时,我得到的是空文本。使用getAttribute时,我得到的复选框的实际名称是$PpyWorkPage$pOutageRequest$pConstructionManagement

constructionMgmnt.getText();
constructionMgmnt.getAttribute("name")
页面来源“如何编码”复选框

<span class="checkbox" data-ctl="Checkbox">
   <input value="false" name="$PpyWorkPage$pOutageRequest$pConstructionManagement" type="hidden">
   <input id="ConstructionManagement" class="checkbox chkBxCtl" value="true" name="$PpyWorkPage$pOutageRequest$pConstructionManagement" validationtype="true-false" pn=".ConstructionManagement" type="checkbox">
   <label class=" cb_standard" for="ConstructionManagement">Construction Management</label>
</span>

谢谢。

使用以下代码查找标签:

//to find the Label Text
@FindBy(how = How.ID, xpath = "//input[@id='ConstructionManagement')//following::label[1]"
private WebElement constructionMgmnt_label;
接下来,您可以使用以下命令检索复选框文本,如下所示:

String my_label = constructionMgmnt_label.getAttribute("innerHTML")
String my_label = constructionMgmnt_label.getAttribute("innerHTML")