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 如何使用WebDriver验证下拉列表的启用禁用值?_Java_Selenium_Xpath_Selenium Webdriver_Automation - Fatal编程技术网

Java 如何使用WebDriver验证下拉列表的启用禁用值?

Java 如何使用WebDriver验证下拉列表的启用禁用值?,java,selenium,xpath,selenium-webdriver,automation,Java,Selenium,Xpath,Selenium Webdriver,Automation,下拉列表中有可以更改的百分比值,有些值被禁用,有些值被启用? 我需要验证该值并检查它是启用还是禁用的 有没有办法获取一个值的XPath并检查其已启用或已禁用 查找图像以获取更多详细信息 您可以使用以下代码检查选项是启用还是禁用。尝试使用下面的代码 WebElement selectDropDown=driver.findElement(By.xpath(".//select[@id='level_points']")); List<WebElement> options=select

下拉列表中有可以更改的百分比值,有些值被禁用,有些值被启用? 我需要验证该值并检查它是启用还是禁用的

有没有办法获取一个值的XPath并检查其已启用或已禁用

查找图像以获取更多详细信息


您可以使用以下代码检查选项是启用还是禁用。尝试使用下面的代码

WebElement selectDropDown=driver.findElement(By.xpath(".//select[@id='level_points']"));
List<WebElement> options=selectDropDown.findElements(By.tagName("option"));
for(int i=0;i<options.size();i++)
{
 try{
    String isDisabled=options.get(i).getAttribute("disabled");
     //Write the required code if disabled
    }
 catch(Exception ex)
   {
    //Write required code if not disabled
   } 
}
WebElement selectDropDown=driver.findElement(By.xpath(“.//select[@id='level\u points']”);
列表选项=selectDropDown.findElements(按.tagName(“选项”));

对于(int i=0;i在firepath中检查一次此xpath//select[@id=level\u points]是否选择了所有选项。如果是,则根据您的要求尝试从中选择选项,如//select[@id=level\u points]//option[@value='100'],然后检查它是否像driver.findElement(By.xpath(“xpath here”)。isEnabled()如果xpath//select[@id=level\u points]不起作用,请验证一次select选项是否在iframe内。如果是,请切换到iframe,然后按照上面的说明操作。谢谢您帮助我捕获元素