我在源代码中有这一部分:
<div class="CFApplyButtonContainer" style="height: 21px;">
<button class="tab-button tab-widget disabled" style="max-width: 67px;" disabled="" type="button">
<span class="icon"></span>
<span class="label">Cancel</span>
</button>
<button class="tab-button tab-widget disabled" style="max-width: 67px;" disabled="" type="button">
<span class="icon"></span>
<span class="label">Apply</span>
</button>
</div>
我的Java部分是这样的:
// detect type of the filter
if (type.equals("")) {
elementList = driver.findElements(By.xpath("//div[@id='" + id + "_menu']//a[@class='FIText']"));
if (elementList.size() > 0) {
if (driver.findElements(By.xpath("//div[@id='" + id + "_menu']//div[@class='CFApplyButtonContainer']//span[@class='label'][text()='Apply']/..")).size() > 0) {
type = "multi_checkbox_with_apply";
}
else {
type = "multi_checkbox_without_apply";
}
}
}
//if apply button enabled
element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='"+id+"_menu']//div[@class='CFApplyButtonContainer']//span[@class='label'][text()='Apply']/..")));
if (element.getAttribute("disabled") == null) {
element.click();
//log("clicked on apply button");
waitForLoadingSpinner();
}
else {
//log("apply button disabled - no need to click on it");
}
// close drop down menu
element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@class='tab-glass clear-glass tab-widget']")));
element.click();
//log("dropdown menu closed");
}
这是找到包含&#34;应用&#34;?的跨度的正确方法吗?我的申请突然停止工作,不知道还有什么可以尝试?
答案 0 :(得分:2)
您可以在标记内搜索文本的唯一方法(查找仅适用于A
标记的链接文本除外)是使用XPath。以下应该得到你想要的。
//div[@class='CFApplyButtonContainer']/button/span[text()='Apply']
像在问题中一样使用它
if (driver.findElements(By.xpath("//div[@class='CFApplyButtonContainer']/button/span[text()='Apply']")).size() > 0)
{
// found the element, do stuff
}