Search code examples
javaseleniumselenium-webdriverpage-factory

Drop down value not captured with selenium page factory


Below is my @findby annotation with method, help to to get the value:

@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()); 
    } 
}

Error getting:

NoSuchElementException: Cannot locate option with value : xyz


Solution

  • make sure you've initialised page factory in constructor with

    PageFactory.initElements(driver, ClassName.class);