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

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

Introduction

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

Prototype

@Override
public void selectByValue(String value) 

Source Link

Document

Select all options that have a value matching the argument.

Usage

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithMultipleFilterAnd() {

    String model = "Veloster";
    String color = "red";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("model")).sendKeys(model);
    driver.findElement(By.name("color")).sendKeys(color);
    Select dropdown = new Select(driver.findElement(By.name("color_logical")));
    dropdown.selectByValue(" AND ");
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();

    String correct_value = "ABC0006";
    assertTrue(newPage.contains(correct_value));
}

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithMultipleFilterOR() {

    String color = "silver";
    String price = "18000.00";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("color")).sendKeys(color);
    driver.findElement(By.name("price")).sendKeys(price);
    Select dropdown = new Select(driver.findElement(By.name("price_logical")));
    dropdown.selectByValue(" OR ");
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();
    System.out.println(newPage);//from  w w w  .  jav  a 2  s  .c  o  m

    String correct_value;
    correct_value = "ABC0006";
    assertTrue(newPage.contains(correct_value));
    correct_value = "ABC0007";
    assertTrue(newPage.contains(correct_value));
}

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;
    }//from   w  w  w  . j a va2s  .co 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 w  w  w .  j  a  va2  s  . c o  m*/
        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.CAOMSearchFormPage.java

License:Open Source License

void enterCollection(final String collection) throws Exception {
    final Select collSelect = new Select(dataTrain.findElement(DATA_TRAIN_COLLECTION_MENU));

    // Unselect the 'All' option
    collSelect.deselectByIndex(0);//from   www. ja  v  a2 s.  c  o  m
    collSelect.selectByValue(collection);
}

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

License:Open Source License

public void enterInstrument(final String instrumentName) {
    final Select instrumentSelect = new Select(dataTrain.findElement(DATA_TRAIN_INSTRUMENT_MENU));

    // Unselect the 'All' option
    instrumentSelect.deselectByIndex(0);
    instrumentSelect.selectByValue(instrumentName);
}

From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java

License:Open Source License

/**
 * Select in a pulldown.//  ww  w. j  a va  2  s  .  co m
 *
 * @param by    The finder element.
 * @param value The value to set.
 * @throws Exception For any test execution exceptions
 */
public void select(final By by, final String value) throws Exception {
    final Select select = new Select(find(by));
    select.selectByValue(value);
}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchActionPerformed

    try {/*from  www  .  j  a va 2  s  .c o  m*/
        //            MarionetteDriverManager.getInstance().setup();
        System.out.println("Mulai Pencarian...");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");
        //      Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;
        String kereta = ((ComboItem) comboKereta.getSelectedItem()).getValue();

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {

            //                    driver = new MarionetteDriver();
            driver = new ChromeDriver();
        }
        //       hmin = Integer.valueOf(args[0]).intValue();
        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;
        boolean keeploop = true;
        while (/**list==null || list.size() == 0**/
        keeploop) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggal.getSelectedIndex());

                ComboItem stFrom = (ComboItem) comboStBerangkat.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(stFrom.getValue());

                ComboItem stTo = (ComboItem) comboStTujuan.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(stTo.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();
                //          Thread.sleep(1000);
                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                if (list != null && list.size() > 0) {
                    List<WebElement> listForm = driver.findElements(By.tagName("form"));
                    for (WebElement form : listForm) {
                        List<WebElement> listInput = form.findElements(By.tagName("input"));
                        for (WebElement input : listInput) {
                            if (input.getAttribute("value").equalsIgnoreCase(kereta)) {
                                WebElement btn = form.findElement(By.className("itButton"));
                                btn.click();
                                System.out.println("========================>KLIK BOOKING");
                                keeploop = false;
                                throw new KlikException("BerhasilKlik");
                            }
                        }
                    }
                }
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (KlikException ke) {
                System.out.println("================> Masuk Klik Exception");
                keeploop = false;
                break;
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }

        //       System.out.println("ada keretaaaaaa: "+list.size());
        List<WebElement> listInput = driver.findElements(By.tagName("input"));
        for (WebElement input : listInput) {
            if (input.getAttribute("type").equals("checkbox")) {
                input.click();
                break;
            }
        }
        WebElement lanjut = driver.findElement(By.cssSelector("input[type='submit'][name='booking']"));
        lanjut.click();

        //Ngisi Tikete 
        //Nunggu disit
        //tunggu sampe page ready, nandainnya kalo element div dengan css class "txt_first_name_adult_1" muncul
        WebElement elementForWait = (new WebDriverWait(driver, 3))
                .until(ExpectedConditions.visibilityOfElementLocated(By.id("txt_first_name_adult_1")));
        //end wait
        WebElement namaPenumpang = driver.findElement(By.id("txt_first_name_adult_1"));
        WebElement ktp = driver.findElement(By.id("txt_passport_1"));

        WebElement contactName = driver.findElement(By.id("txt_contact_first_name"));
        WebElement contactEmail = driver.findElement(By.id("txt_contact_email"));
        WebElement contactPhone = driver.findElement(By.id("txt_contact_phone"));
        WebElement contactAddress = driver.findElement(By.id("txt_contact_home_address"));

        namaPenumpang.sendKeys(txtNamaPenumpang.getText());
        ktp.sendKeys(txtNoKTP.getText());
        contactName.sendKeys(txtNamaPenumpang.getText());
        contactEmail.sendKeys(txtEmail.getText());
        contactPhone.sendKeys(txtNoTelp.getText());
        contactAddress.sendKeys(txtAlamat.getText());

        playSound();

        JOptionPane.showMessageDialog(rootPane,
                "Booking sudah tersedia, Silakan inputkan Captcha!! Dan lanjutkan secara manual", "Informasi",
                JOptionPane.INFORMATION_MESSAGE);
        this.setAlwaysOnTop(true);

        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.arifnazarpurwandaru.selenium.MainFrame.java

private void btnSearchBiasaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchBiasaActionPerformed

    try {/*w ww. j a  v a 2s. c  o m*/
        Runtime.getRuntime().exec("TASKKILL /F /IM Firefox.exe");
        Runtime.getRuntime().exec("TASKKILL /F /IM iexplore.exe");

        WebDriver driver = null;

        //use proxy
        if (radioUseProxy.isSelected()) {
            String proxyHost = hostProxy.getText() + ":" + portProxy.getText();
            Proxy proxy = new Proxy();
            proxy.setHttpProxy(proxyHost);
            proxy.setSslProxy(proxyHost);
            proxy.setFtpProxy(proxyHost);
            proxy.setSocksUsername(usernameProxy.getText());
            proxy.setSocksPassword(new String(passwordProxy.getPassword()));

            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(CapabilityType.PROXY, proxy);

            driver = new ChromeDriver(cap);
        } else {
            driver = new ChromeDriver();
        }

        ComboItem link = (ComboItem) comboLink.getSelectedItem();
        driver.get(link.getValue());
        List<WebElement> list = null;
        int counter = 1;

        while (list == null || list.size() == 0) {

            try {
                Select selectTgl = new Select(driver.findElement(By.name("tanggal")));
                selectTgl.selectByIndex(comboTanggalBiasa.getSelectedIndex());

                ComboItem ck = (ComboItem) comboStBerangkatBiasa.getSelectedItem();
                Select selectFrom = new Select(driver.findElement(By.name("origination")));
                selectFrom.selectByValue(ck.getValue());

                ComboItem ct = (ComboItem) comboStTujuanBiasa.getSelectedItem();
                Select selectTo = new Select(driver.findElement(By.name("destination")));
                selectTo.selectByValue(ct.getValue());

                Select selectAdult = new Select(driver.findElement(By.name("adult")));
                selectAdult.selectByValue("1");

                WebElement element = driver.findElement(By.name("Submit"));
                element.click();

                //tunggu sampe page ready, nandainnya kalo element div dengan css class "itReservationContent" muncul
                WebElement elementForWait = (new WebDriverWait(driver, 1)).until(
                        ExpectedConditions.visibilityOfElementLocated(By.className("itReservationContent")));
                //end wait

                list = driver.findElements(By.className("itButton"));
                System.out.println("==========================> looping ke: " + counter);
                counter++;
            } catch (Exception e) {
                System.out.println("===================> Reconecting..." + link.getValue());
                driver.get(link.getValue());
            }
        }
        System.out.println("ada keretaaaaaa: " + list.size());
        System.out.println("DONE");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:com.autocognite.appium.lib.base.AbstractAppiumUiDriver.java

License:Apache License

public void selectDropDownValue(Select selectElement, String value) {
    selectElement.selectByValue(value);
}