Example usage for org.openqa.selenium By cssSelector

List of usage examples for org.openqa.selenium By cssSelector

Introduction

In this page you can find the example usage for org.openqa.selenium By cssSelector.

Prototype

public static By cssSelector(String cssSelector) 

Source Link

Document

Find elements via the driver's underlying W3C Selector engine.

Usage

From source file:com.actian.amc.pages.InstanceNewPage.java

public InstanceNewPage instanceCreationWizardScreen3(String nodeConfig, String numNodes,
        String instanceOption) {//from  w w w . j a  va  2  s . com

    try {
        // Node Configuration choice
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        List<String> nodeConfigList = Arrays.asList("Extra Small", "Small", "Medium", "Large", "Custom");
        if (nodeConfigList.contains(nodeConfig)) {
            String nodeConfigChoice = "input[name='" + nodeConfig + "']";
            driver.findElement(By.cssSelector(nodeConfigChoice)).click();
        }
        // If the Node Configuration is custom
        if (nodeConfig == "Custom") {
            driver.findElement(numDataNodes).clear();
            driver.findElement(numDataNodes).sendKeys(numNodes);
        }
        // added instnace option for Vector H
        List<String> instanceOptions = Arrays.asList("Development", "Balanced price and performance",
                "Production");
        if (instanceOptions.contains(instanceOption)) {
            String instanceChoice = "input[name='" + instanceOption + "']";
            driver.findElement(By.cssSelector(instanceChoice)).click();
        }
        // Node size choices for AWS when deploying AMC
        List<String> nodeSizeList = Arrays.asList(
                "$$$$: 4 CPU, 16GB, 1 x 8GB + 1 x 25GB, High Performance Network",
                "$$: 2 CPU, 8GB, 1 x 8GB + 1 x 25GB", "$: 2 CPU, 4GB, 1 x 8GB + 1 x 25GB");

        if (nodeSizeList.contains(instanceOption)) {
            if (driver.findElements(nodeSizeDropDown).size() > 0) {
                selectNodeSize(instanceOption);
            }
        }
        // Instance Options
        if ((instanceOption.contains("Virtual")) || (instanceOption.contains("Mixed"))
                || (instanceOption.contains("OnMetal"))) {
            String instOption = "input[name='" + instanceOption + "']";
            driver.findElement(By.cssSelector(instOption)).click();
        }
        clickWizardButton("Wizard 3: ", "Next");
    } catch (NoSuchElementException | StaleElementReferenceException e) {
        System.out.println("Trying to recover from a NoSuchElementException :-");

    }
    return new InstanceNewPage(driver);
}

From source file:com.algomedica.service.AlgomedicaTest.java

@Test
public void Login() throws InterruptedException {

    WebElement Username = driver.findElement(By.cssSelector("[name='username']"));
    Username.sendKeys("koutuk");

    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    WebElement password = driver.findElement(By.cssSelector("[name='password']"));
    password.sendKeys("koutuk");

    driver.findElement(By.cssSelector(".btn.btn-lg.btn-success.btn-block")).click();

}

From source file:com.algomedica.service.AlgomedicaTest.java

@Test
public void NewCustomerCreation() throws InterruptedException {

    driver.findElement(By.cssSelector("[class='btn btn-success pull-left']")).click();

    WebElement orgName = driver.findElement(By.id("orgName"));
    orgName.sendKeys("Apollo");

    WebElement personName = driver.findElement(By.id("personName"));
    personName.sendKeys("rakesh");

    WebElement personEmailId = driver.findElement(By.id("personEmailId"));
    personEmailId.sendKeys("rakesh.pandey@silicus.com");

    WebElement contact1 = driver.findElement(By.id("contact1"));
    contact1.sendKeys("9873459870");

    WebElement contact2 = driver.findElement(By.id("contact2"));
    contact2.sendKeys("9345098789");

    WebElement country = driver.findElement(By.id("country"));
    country.sendKeys("India");

    WebElement city = driver.findElement(By.id("city"));
    city.sendKeys("Pune");

    WebElement State = driver.findElement(By.id("State"));
    State.sendKeys("Maharashtra");

    WebElement PIN = driver.findElement(By.id("PIN"));
    PIN.sendKeys("83459");

    WebElement address1 = driver.findElement(By.id("address1"));
    address1.sendKeys("RH no #92");

    WebElement address2 = driver.findElement(By.id("address2"));
    address2.sendKeys("RH no #93");

    driver.findElement(By.cssSelector("[class='btn btn-success ng-scope']")).click();

}

From source file:com.algomedica.service.AlgomedicaTest.java

@Test
public void NewMachineDetails() throws InterruptedException {

    driver.findElement(By.cssSelector("[class='btn btn-primary pull-left']")).click();

    WebElement MACNo = driver.findElement(By.id("MACNo"));
    MACNo.sendKeys("985921113716");

    WebElement DeviceModel = driver.findElement(By.id("Device Model #"));
    DeviceModel.sendKeys("Dell Thinkpad");

    WebElement DeviceBrandName = driver.findElement(By.id("Device Brand Name"));
    DeviceBrandName.sendKeys("Dell");

    Select lsType = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[1]/div/select")));
    ;//from   w w w  . j  a va 2  s . c om
    lsType.selectByVisibleText("Trial");

    Select LicenseCategory = new Select(driver.findElement(By.xpath(
            ".//*[@id='page-wrapper1']/div[3]/div/div[2]/div/div[2]/div[3]/div/form/fieldset/div[2]/div[2]/div/select")));
    LicenseCategory.selectByVisibleText("Small");

    WebElement LicenseValidity = driver.findElement(By.id("License Validity"));
    LicenseValidity.sendKeys("30");

    WebElement LicenseCost = driver.findElement(By.id("License Cost"));
    LicenseCost.sendKeys("99");

    WebElement salesOpsName = driver.findElement(By.id("Sales Ops Personnel Name"));
    salesOpsName.sendKeys("rahul");

    WebElement SendEmailTo = driver.findElement(By.id("Send Email To"));
    SendEmailTo.sendKeys("rakesh.pandey@silicus.com");

    driver.findElement(By.cssSelector("[class='btn btn-success ng-scope']")).click();

    Thread.sleep(3000);
    driver.findElement(By.cssSelector("button[class='close']")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[1]/a")).click();

    Thread.sleep(3000);
    driver.findElement(By.xpath(".//*[@id='wrapper']/nav/ul/li[2]/a")).click();

    Thread.sleep(3000);
    driver.close();

}

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

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

    try {//www .  j  av a  2s  . c om
        //            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.atanas.kanchev.testframework.selenium.handlers.Finder.java

License:Apache License

/**
 * {@inheritDoc}/*from  w w w.  j a va2 s .  co  m*/
 */
@Override
public Finder byAttributeValue(String attribute, String value) {

    if (attribute == null || value == null)
        throw new CustomExceptions.Common.NullArgumentException();
    else
        ((SeleniumContext) context().getCurrentContext())
                .setCurrentElement(findElement(By.cssSelector("[" + attribute + "='" + value + "']")));

    return this;
}

From source file:com.atlassian.jira.pageobjects.pages.admin.licenserole.LicenseRolePage.java

public List<Role> roles() {
    return copyOf(transform(roles.findAll(By.cssSelector("tbody tr")), TOROLE));
}

From source file:com.atlassian.jira.pageobjects.pages.admin.licenserole.LicenseRolePage.java

public Role role(String id) {
    final PageElement element = roles.find(By.cssSelector(String.format("tbody tr[data-id='%s']", id)));
    if (!element.isPresent()) {
        throw new IllegalArgumentException(String.format("Can't find role with id '%s'.", id));
    }//from www  . j  a v a 2 s. com
    return new Role(element);
}

From source file:com.atlassian.jira.pageobjects.pages.admin.ViewLicensePage.java

public String getOrganisation() {
    return licenseTable.find(By.cssSelector("tr:nth-child(1) td:nth-child(2) b")).getText();
}

From source file:com.atlassian.jira.pageobjects.pages.admin.ViewLicensePage.java

public Date getDatePurchased() {
    String datePurchased = licenseTable.find(By.cssSelector("tr:nth-child(2) td:nth-child(2) b")).getText();
    SimpleDateFormat format = new SimpleDateFormat("dd/MM/yy");

    Date date;/*from  www . ja  va2 s .c o  m*/
    try {
        date = format.parse(datePurchased);
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }

    return date;
}