Java 使用cssSelector或xPath Selenium Web驱动程序在筛选器上应用按钮?
我在资料来源中有这一部分:Java 使用cssSelector或xPath Selenium Web驱动程序在筛选器上应用按钮?,java,selenium,selenium-webdriver,selenium-ide,Java,Selenium,Selenium Webdriver,Selenium Ide,我在资料来源中有这一部分: <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 cla
<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>
这是查找包含“Apply”的范围的正确方法吗?我的apply突然停止工作,不知道还能尝试什么?搜索标记内文本的唯一方法(除了查找仅适用于
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
}
搜索标记内的文本的唯一方法(而不是查找仅适用于
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
}
您好,谢谢您的帮助,但当我将以下内容放入时:if(driver.findElements(By.xpath(“//div[@class='CFApplyButtonContainer']/button/span[text()='Apply'])).size()>0)它只是停止,没有任何作用,不知何故,使用此size()>0不想单击Apply按钮。如果我上面提供的语句没有点击,我不知道该怎么办,所以我假设你在别处点击?考虑到您提供的HTML,这个XPath是有效的。如果你添加了内容,正如你在问题中所显示的,没有更多信息,我无法帮助你。您好,你的解决方案正在运行,只是我在某一点上遇到了过滤问题,不知道如何跳过该部分。但是非常感谢!您好,谢谢您的帮助,但当我将以下内容放入时:if(driver.findElements(By.xpath(“//div[@class='CFApplyButtonContainer']/button/span[text()='Apply'])).size()>0)它只是停止,没有任何作用,不知何故,使用此size()>0不想单击Apply按钮。如果我上面提供的语句没有点击,我不知道该怎么办,所以我假设你在别处点击?考虑到您提供的HTML,这个XPath是有效的。如果你添加了内容,正如你在问题中所显示的,没有更多信息,我无法帮助你。您好,你的解决方案正在运行,只是我在某一点上遇到了过滤问题,不知道如何跳过该部分。但是非常感谢!