Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

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

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:com.amolik.scrapers.OdishaRationCardScraper.java

public static void waitForSubmit(WebDriver driver, String emptyText, String dataText) {

    By byText = By.xpath("//table[@id='gvDist']/tbody/tr[1]/td[1][text()='" + emptyText + "']" + "|"
            + "//table[@id='gvDist']/tbody/tr[3]/td[6][contains(text(),'" + dataText + "')]");

    WebElement element = new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(byText));
}

From source file:com.androidwhy.modules.test.selenium.Selenium2.java

License:Apache License

/**
 * Conditions, timeout??.//from w w w.j  a v  a2s .c  om
 * 
 * @see #waitForTextPresent(By, String, int)
 * @see ExpectedConditions
 */
public void waitForCondition(ExpectedCondition conditon, int timeout) {
    (new WebDriverWait(driver, timeout)).until(conditon);
}

From source file:com.arcbees.test.ElementLocator.java

License:Apache License

private WebElement doFindElement() {
    if (timeout > 0) {
        return new WebDriverWait(webDriver, timeout).until(ExpectedConditions.presenceOfElementLocated(by));
    } else {//ww w  .  j av  a 2s .c om
        return webDriver.findElement(by);
    }
}

From source file:com.arcbees.test.ElementLocator.java

License:Apache License

private List<WebElement> doFindElements() {
    if (timeout > 0) {
        return new WebDriverWait(webDriver, timeout)
                .until(ExpectedConditions.presenceOfAllElementsLocatedBy(by));
    } else {//from w ww . ja  v a2  s  .c o m
        return webDriver.findElements(by);
    }
}

From source file:com.ariatemplates.seleniumjavarobot.DebuggableChrome.java

License:Apache License

public DebuggableChrome() {
    ChromeOptions options = new ChromeOptions();
    String debugExtension = System.getProperty("seleniumjavarobot.chrome.debugextension");
    if (debugExtension == null || !new File(debugExtension).isDirectory()) {
        throw new RuntimeException(
                "Please set the seleniumjavarobot.chrome.debugextension system property to point to the path of the chrome extension.");
    }//from www.ja va  2 s.com
    options.addArguments("load-extension=" + debugExtension);
    options.addArguments("start-maximized");
    webdriver = new ChromeDriver(options);
    // waits for the extension page to be loaded:
    (new WebDriverWait(webdriver, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("selenium-java-robot")));
    webdriver.manage().timeouts().setScriptTimeout(1, TimeUnit.DAYS);
}

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

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

    try {/*from  ww w .  j a va 2  s .  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.arifnazarpurwandaru.selenium.MainFrame.java

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

    try {/* w w  w.  ja va 2  s  .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.artnaseef.webapp.test.SimpleTest.java

License:Apache License

@Test
public void testSimple() throws Exception {
    this.driver.get(this.serverUrl + "index.html");

    String whoToSend = "foo";

    WebElement who = this.driver.findElement(By.id("who"));
    who.sendKeys(whoToSend);//  ww  w  .jav  a 2s.c o  m

    WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
    sendBtn.click();

    // wait 5 secs for ajax response
    new WebDriverWait(this.driver, 5)
            .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

    WebElement response = this.driver.findElement(By.id("response"));
    String text = response.getText();

    Assert.assertEquals("Hello " + whoToSend, text);

}

From source file:com.atanas.kanchev.testframework.selenium.handlers.Interact.java

License:Apache License

/**
 * {@inheritDoc}//w w  w .j a v a2  s  .  c om
 */
@Override
public Interact handleAlert(boolean accept) {
    try {
        new WebDriverWait(((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver(),
                DriverConfig.DEFAULT_IMPL_WAIT).until(ExpectedConditions.alertIsPresent());
        Alert alert = ((SeleniumContext<WebDriver>) context().getCurrentContext()).getDriver().switchTo()
                .alert();
        if (accept)
            alert.accept();
        else
            alert.dismiss();

    } catch (NoAlertPresentException e) {

    }

    return this;
}

From source file:com.atanas.kanchev.testframework.selenium.handlers.NavigateSelenium.java

License:Apache License

/**
 * {@inheritDoc}/* ww  w .j a  va  2s  .  c om*/
 */
@Override
public INavigateSelenium waitForFrameByIdToBeAvailableAndSwitch(String frameId) {
    try {
        new WebDriverWait(driver, 5).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameId));

    } catch (NoSuchFrameException nsfe) {
        logger.error("Unable to Switch Frame - No Such Frame");

    }
    return this;
}