硒页面工厂未捕获下拉值

Drop down value not captured with selenium page factory

下面是我的@findby注释方法,有助于获取值:

@FindBy(how = How.XPATH, using = "//*[@id='Voucher']") 
public WebElement DropDownVoucherName;

public void voucher_ddp(String vddp) { 
    try { 
        Select vdp = new Select(DropDownVoucherName); vdp.selectByValue(vddp); 
    } catch (Exception e) { 
        System.out.println("Error found: "+e.getMessage()); 
    } 
}

获取错误:

NoSuchElementException: Cannot locate option with value : xyz

确保您已使用

在构造函数中初始化页面工厂
PageFactory.initElements(driver, ClassName.class);