繁体   English   中英

选择下拉选项不适用于Selenium

[英]Selecting dropdown option is NOT working with Selenium

package com.test.utitlity;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

public class selectDropdown extends globalVariables {   
    public static void select(String locator, int indexValue) {

     Select select= new Select(common.getObject(locator));
     //select.selectByValue("selectValue");
     System.out.println(indexValue);
     select.selectByIndex(indexValue);   
    }

}

它是单击下拉列表,但未选择选项。下拉列表为空。如何解决此问题? 但是,当我运行调试模式时,它正在按预期方式工作。 添加了等待条件,但得到了IllegalStateException。

您可以尝试以下一种方法,让我知道结果如何。

WebDriverWait  Test_Wait = new WebDriverWait(driver, 10);
WebElement Drop_down = Test_Wait.until(ExpectedConditions.elementToBeClickable(common.getObject(locator)));
 List<WebElement> lst2 = Drop_down.findElements(By.xpath(".//option[contains(text(),'Your_Option_Text')]"));
 for (WebElement option : lst2)
    {
        if (!option.isSelected())
               {
                  option.click();
                }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM