0

Hi I am using Page Factory to keep all my locator in a class .

@FindBy(xpath="//select[@ng-model='selectedLeadSource']")
    WebElement source_of_lead;
    public Select getSourceOptions() {
        return new Select(source_of_lead);
    }

But I am not able to use wait as its throwing me an error.

wait.until(ExpectedConditions.elementToBeClickable(onPage.getSourceOptions().selectByValue("Campaign")));

Error :

The method elementToBeClickable(By) in the type ExpectedConditions is not applicable for the arguments (void)

Cod
  • 179
  • 1
  • 12

3 Answers3

0

Use This::WebDriverWait wait = new WebDriverWait(driver, 100);

@FindBy(xpath="//select[@ng-model='selectedLeadSource']")

WebElement source_of_lead; element=wait.until(ExpectedConditions.presenceOfElementLocated(source_of_lead));

Select dropdown = new Select (element); dropdown.selectByValue("Campaign");

0

ExpectedConditions.elementToBeClickable accepts either By or web element. You can use 1. elementSelectionStateToBe(By locator, boolean selected)  Or 2. elementSelectionStateToBe(WebElement element, boolean selected)

An expectation for checking if the given element is selected.

Magesh
  • 308
  • 1
  • 4
  • 18
0

You cannot use wait methods when using the Page Factory. The below code creates an implicit wait of however many seconds you want to use. I used 15 in my example.

When you initialize your page object, use the AjaxElementLocatorFactory.

public LoginPage(WebDriver driver) {
       this.driver = driver;
        PageFactory.initElements(new AjaxElementLocatorFactory(driver, 15), this);
}
Bill Hileman
  • 2,798
  • 2
  • 17
  • 24