Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用cssSelector或xPath Selenium Web驱动程序在筛选器上应用按钮?_Java_Selenium_Selenium Webdriver_Selenium Ide - Fatal编程技术网

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是有效的。如果你添加了内容,正如你在问题中所显示的,没有更多信息,我无法帮助你。您好,你的解决方案正在运行,只是我在某一点上遇到了过滤问题,不知道如何跳过该部分。但是非常感谢!