【发布时间】:2018-09-07 21:13:09
【问题描述】:
您好,我正在尝试捕获位于同一跨度类中的复选框旁边的名称,但该名称位于标签标签中。尝试使用 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>
谁能想到如何从指向复选框 ID 的元素中获取文本,或者我必须使用 xpath 来标记以获取该复选框旁边的文本?
//example of garbing the name of the Label (I tested this and it works)
driver.findElement(By.xpath("//label[@for='ConstructionManagement']"));
谢谢。
【问题讨论】:
标签: selenium selenium-webdriver checkbox