0
你好我试图捕获名称位于标签标签中的复选框旁边的名称是在相同的跨度类中。当试图使用getText()方法捕获文本时,我得到空名称。Selenium Webdriver捕获复选框文本
在代码中显示它如何操作。
//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']"));
谢谢。
感谢您的快速回放。 –
@TomaszWida如果迎合您的问题,请接受答案。谢谢 – DebanjanB