Example usage for org.openqa.selenium.support.ui Select getFirstSelectedOption

List of usage examples for org.openqa.selenium.support.ui Select getFirstSelectedOption

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui Select getFirstSelectedOption.

Prototype

@Override
public WebElement getFirstSelectedOption() 

Source Link

Usage

From source file:administrationedit.setSeasonTemplate.java

public static void main(String[] args) throws InterruptedException {

    for (int y = 0; y < 2; y++) {

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 3);
        driver.manage().window().maximize();

        Random r = new Random();

        Faker faker = new Faker();

        driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd");

        adminLogin login = new adminLogin(driver);
        login.loginToAdmin("demo", "demo");

        int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y;
        String curYear = String.valueOf(currentYear);

        // Input name of template
        driver.findElement(By.id("name")).sendKeys("Season-" + curYear);

        // Choose year
        Select year = new Select(driver.findElement(By.id("year")));
        year.selectByVisibleText(curYear);

        // Now select seasons
        WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']"));
        if (year.getFirstSelectedOption().getText().equals(curYear)) {
            String id = tableId.getAttribute("id");

            for (int i = 1; i <= 12; i++) {
                Thread.sleep(1000);
                for (int j = 1; j <= 7; j++) {
                    if (!driver.findElements(By.xpath(
                            "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                            .isEmpty()) {
                        driver.findElement(By.xpath(
                                "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                                .click();
                        break;
                    }//  w  w w.ja  va2 s  .c o  m
                }
                i++;
                int weeks = driver
                        .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr"))
                        .size();

                int test = 0;
                for (int j = 7; j >= 1; j--) {
                    if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr["
                            + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                        test = 1;
                        break;
                    } else
                        test = 2;
                }
                switch (test) {
                case 1:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season1 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season1int = r.nextInt(season1.getOptions().size() - 1) + 1;
                            season1.selectByIndex(season1int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                    break;
                case 2:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season2 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season2int = r.nextInt(season2.getOptions().size() - 1) + 1;
                            season2.selectByIndex(season2int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                }
            }
        }

        // SAVE
        wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")));
        driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))
                .click();
        if (driver.getTitle().equals("Accommodation season templates administration")) {
            driver.close();
        }
    }
}

From source file:applicationdriverlayer.pageobjects.squash.booking.CourtAndTimeSlotChooserPage.java

License:Apache License

public CourtAndTimeSlotChooserPage selectDate(java.time.LocalDate date) {

    Select dateSelect = new Select(dateDropdown);
    if (java.time.LocalDate.parse(dateSelect.getFirstSelectedOption().getText(),
            DateTimeFormatter.ofPattern("EE, d MMM, yyyy")).equals(date)) {
        // Date is already selected so just return
        return this;
    }/*w w  w.  j  av a  2s  .c o  m*/
    dateSelect.selectByValue(date.toString() + ".html");

    // Click Go if javascript is disabled (but not otherwise or might get
    // staleref exception)
    String javascriptEnabled = System.getProperty("WebDriverJavascriptEnabled");
    if (javascriptEnabled.equals("false")) {
        dateGoButton.click();
    }

    // Wait for booking page for new date to load fully
    return this.get(true, getCachedWebElement(), Optional.of(false));
}

From source file:at.tugraz.ist.catroweb.catroid.ProfileTests.java

License:Open Source License

@Test(dataProvider = "loginAndChangeData", groups = { "functionality",
        "visibility" }, description = "check profile page")
public void profilePageChangeUserData(HashMap<String, String> dataset) throws Throwable {
    try {//from ww w  .  java 2s. com
        openLocation("registration/");

        driver().findElement(By.id("registrationUsername")).sendKeys(dataset.get("registrationUsername"));
        driver().findElement(By.id("registrationPassword")).sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("registrationEmail")).sendKeys(dataset.get("registrationEmail"));
        driver().findElement(By.id("registrationMonth")).sendKeys(dataset.get("registrationMonth"));
        driver().findElement(By.id("registrationYear")).sendKeys(dataset.get("registrationYear"));
        driver().findElement(By.id("registrationGender")).sendKeys(dataset.get("registrationGender"));
        (new Select(driver().findElement(By.id("registrationCountry"))))
                .selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("registrationCity")).sendKeys(dataset.get("registrationCity"));
        driver().findElement(By.id("registrationSubmit")).click();
        ajaxWait();

        assertTrue(isTextPresent(dataset.get("registrationUsername")));
        assertEquals(dataset.get("registrationEmail"),
                driver().findElement(By.xpath("//*[@id='profileEmail']/input")).getAttribute("value"));

        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isVisible(By.xpath("//*[@id='profileNewPassword']/input")));
        assertTrue(isVisible(By.xpath("//*[@id='profileRepeatPassword']/input")));
        assertTrue(isVisible(By.id("profileSaveChanges")));

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("changedPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent(CommonStrings.PROFILE_PASSWORD_DIDNT_MATCH));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("emptyPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("emptyPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("shortPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("shortPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("Your password must have at least 6 characters."));

        openLocation("profile/");
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        driver().findElement(By.xpath("//*[@id='profileNewPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.xpath("//*[@id='profileRepeatPassword']/input"))
                .sendKeys(dataset.get("registrationPassword"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        By countrySelect = By.xpath("//*[@id='wrapper']/article/div[1]/div[2]/div[1]/div[4]/select");
        Select selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("registrationCountry"), selectCountry.getFirstSelectedOption().getText());

        selectCountry.selectByValue(dataset.get("changedCountryID"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("changedCountry"), selectCountry.getFirstSelectedOption().getText());

        selectCountry.selectByValue(dataset.get("registrationCountryID"));
        driver().findElement(By.id("profileSaveChanges")).click();
        ajaxWait();

        assertTrue(isTextPresent("saved!"));

        openLocation("profile/");
        selectCountry = new Select(driver().findElement(countrySelect));
        assertEquals(dataset.get("registrationCountry"), selectCountry.getFirstSelectedOption().getText());

        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
    } catch (AssertionError e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    } catch (Exception e) {
        CommonFunctions.deleteUserFromDatabase(dataset.get("registrationUsername"));
        captureScreen("ProfileTests.profilePage." + dataset.get("registrationUsername"));
        throw e;
    }
}

From source file:ca.nrc.cadc.search.integration.SearchResultsPage.java

License:Open Source License

String getSelectedRestFrameEnergyUnit() throws Exception {
    final Select rfUnitSelect = new Select(gridContainer.findElement(REST_FRAME_ENERGY_UNIT_SELECT_LOCATOR));
    final WebElement rfUnitSelectedOption = rfUnitSelect.getFirstSelectedOption();

    return rfUnitSelectedOption.getText();
}

From source file:ca.nrc.cadc.search.integration.SearchResultsPage.java

License:Open Source License

String getSelectIQUnit() throws Exception {
    final Select iqUnitSelectElement = new Select(gridContainer.findElement(IQ_UNIT_SELECT_LOCATOR));
    return iqUnitSelectElement.getFirstSelectedOption().getText();
}

From source file:com.citrix.g2w.webdriver.pages.registration.RegistrationPage.java

License:Open Source License

/**
 * Gets the selected webinar key details for a recurring webinar serires
 * @return selectedSession selected webinar key 
 *///from w w  w.  java2 s  . co m
public String getSelectedRecurringWebinarKey() {
    Select select = new Select(recurringWebinarTimesSelect);
    String selectedSession = select.getFirstSelectedOption().getAttribute("value");
    this.logger.log("Selected webinar key in registration page :" + selectedSession);
    return selectedSession;
}

From source file:com.continuuity.test.page.CreatePage.ClustertemplatesInstancePage.java

License:Apache License

public ClusterDefaults getClusterDefaults() throws JSONException {
    Select select = new Select(globalDriver.findElement(PROVIDER));
    String provider = select.getFirstSelectedOption().getAttribute(Constants.TEXT);

    select = new Select(globalDriver.findElement(HARDWARETYPE));
    String hardwaretype = select.getFirstSelectedOption().getAttribute(Constants.TEXT);

    select = new Select(globalDriver.findElement(IMAGETYPE));
    String imagetype = select.getFirstSelectedOption().getAttribute(Constants.TEXT);

    String dnsSuffix = globalDriver.findElement(DNS_SUFFIX).getAttribute(Constants.VALUE);

    String config = globalDriver.findElement(CONFIG).getAttribute(Constants.VALUE);
    JsonObject configJson = gson.fromJson(config, JsonObject.class);

    Set<String> services = Sets.newHashSet();
    for (WebElement element : globalDriver.findElement(DEFAULT_SERVICE).findElements(DEFAULT_SERVIE_ENTRY)) {
        services.add(element.getAttribute(Constants.INNER_HTML));
    }//ww w.  ja v  a  2  s.  c  o  m

    return new ClusterDefaults(services, provider, hardwaretype, imagetype, dnsSuffix, configJson);
}

From source file:com.continuuity.test.page.CreatePage.HardwaretypesInstancePage.java

License:Apache License

public Map<String, String> getProviderMap() {
    Map<String, String> providerMap = Maps.newHashMap();
    List<WebElement> providers = globalDriver.findElements(PROVIDER);
    List<WebElement> flavors = globalDriver.findElements(FLAVOR);
    for (int i = 0; i < providers.size(); i++) {
        Select select = new Select(providers.get(i));
        providerMap.put(select.getFirstSelectedOption().getText(),
                flavors.get(i).getAttribute(Constants.VALUE));
    }/* w w  w.j a  v a  2 s  . c o  m*/
    return providerMap;
}

From source file:com.continuuity.test.page.CreatePage.ImagetypesInstancePage.java

License:Apache License

public Map<String, String> getProviderMap() {
    Map<String, String> providerMap = Maps.newHashMap();
    List<WebElement> providers = globalDriver.findElements(PROVIDER);
    List<WebElement> flavors = globalDriver.findElements(Image);
    for (int i = 0; i < providers.size(); i++) {
        Select select = new Select(providers.get(i));
        providerMap.put(select.getFirstSelectedOption().getText(),
                flavors.get(i).getAttribute(Constants.VALUE));
    }//from w  ww  .  j a  va  2s  .  c om
    return providerMap;
}

From source file:com.continuuity.test.page.CreatePage.ProvidersInstancePage.java

License:Apache License

public String getProvisioner() {
    Select select = new Select(globalDriver.findElement(PROVISIONER));
    return select.getFirstSelectedOption().getText();
}