简体   繁体   中英

Selenium java trying to click list element

I'm trying to test delta.com site via selenium webDriver and I'm stuck on the passenger info page, instructions how to get to it below. Everything goes just fine except that I can't select any list fields. List opens, programm doesn't select anything and goes further.

So for example I'm trying to select gender.

@FindBy(xpath = "//*[@id=\"gender0-button\"]/span[1]")
private WebElement genderSelection;
@FindBy(xpath = "//*[@id="gender0-menu"]/li[2]")
private WebElement genderMale;

public void setGender(){
    genderSelection.click();
    genderMale.click();
}

But it doesn't select anything, goes further.

Then I tried to use <select> that is hidden, xpath = "//*[@id="gender0"]". There I click on the option with 'male' text. Doesn't work too.

Then I tryed javascript. There are some attributes in <span> that change if I manually change to 'Male'. So i do smth like this (id to set can vary):

js.executeScript("arguments[0].innerText = 'Male'", genderMale);
js.executeScript("document.getElementById('gender0-button').setAttribute('aria-activedescendant', 'ui-id-74')");
js.executeScript("document.getElementById('gender0-button').setAttribute('aria-lablelledby', 'gender0-label ui-id-74 gender0-required')");

This doesn't work too. It sets text into span, but then I still get error that I havn't filled gender field.

So may be someone knows how set at least gender.

How to get to passenger info page: Book a trip -> Flight -> Round trip -> From-to(I select JFK-SVO) -> any dates this month -> Exact dates -> Money -> Find flights -> select any tickets types -> Continue -> you are there.

Edit 1. HTML of the page

Solved. I needed to highlight 'Male' option and then click.

genderSelection.click();
genderMale.sendKeys("Male");
genderMale.click();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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