1
votes

Trying to select 2nd value from Drop down. Drop down is made up of div class.

From constants class:

public static final String HOME_PAGE_FLYING_FROM_ID = "departureAirport";
public static final String FLYING_FROM_AJAX_XPATH = "//div[contains(@class,'autocompletebox') and (rel,'departureAirport')]/p[2]/a";

from my FlightSearch class:

    @FindBy(how = How.ID, using = HOME_PAGE_FLYING_FROM_ID)
        WebElement flyingFrom;

        @FindBy(how = How.XPATH, using = FLYING_FROM_AJAX_XPATH)
        WebElement flyingFromAjaxValue;

public void simpleFlighSearch() {

        flyingFrom.sendKeys("new");
        action.moveToElement(flyingFromAjaxValue).click().build().perform();
        LOGGER.debug("clicked`");

    }

This is the error I am getting it: invalid selector: Unable to locate an element with the xpath expression. Failed to execute 'evaluate' on 'Document'.

1
Not sure but could it be that you should refer to the rel attribute as ... and @rel='departureAirport' ? - buftlica
Post relevant portion of the HTML that you expect your XPath should return - har07

1 Answers

0
votes

Most likely you missed another 'contains' and '@' in your XPath, and it should look like this:

//div[contains(@class,'autocompletebox') and contains(@rel,'departureAirport')]/p[2]/a