Example usage for org.openqa.selenium.support.ui ExpectedConditions elementToBeClickable

List of usage examples for org.openqa.selenium.support.ui ExpectedConditions elementToBeClickable

Introduction

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

Prototype

public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) 

Source Link

Document

An expectation for checking an element is visible and enabled such that you can click it.

Usage

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Clicks (the current element) when the element can be clicked (visibility, enabled etc)
 *
 * @example ClickWhenClickable/*from   ww  w.ja v a  2 s.c  om*/
 * @section Clicks
 */
@SubSteps.Step("ClickWhenClickable")
public void clickWhenClickable() {

    WebElement currentElement = webDriverContext().getCurrentElement();

    waitUntil(ExpectedConditions.elementToBeClickable(currentElement));

    currentElement.click();

}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Finds a button that contains the specified text, waits until the element is clickable, then clicks it.
 *
 * @example ClickButton containing "button text"
 *
 * @section Clicks//ww w  .  jav  a  2 s  . co  m
 * @param text the text to partially match against the button text
 */
@SubSteps.Step("ClickButton containing \"([^\"]*)\"")
public void clickButtonContainingText(String text) {

    final By by = WebDriverSubstepsBy.ByTagContainingText("button", text);

    waitFor(by, "expecting an element with tag", "button", "and text", text);

    logger.debug("about to wait until element clickable");
    waitUntil(ExpectedConditions.elementToBeClickable(by));

    logger.debug("element should be clickable");

    this.webDriverContext().getCurrentElement().click();
}

From source file:com.technophobia.webdriver.substeps.impl.ActionWebDriverSubStepImplementations.java

License:Open Source License

/**
 * Click a button that has the text, NB surrounding quotes are optional
 *
 * @example ClickButton "submit button"/*from  w  ww . j  a  v a 2  s  .c  o  m*/
 * @section Clicks
 * @param buttonText
 *            the button text
 */
@SubSteps.Step("ClickButton \"?([^\"]*)\"?")
public void clickButton(String buttonText) {

    final By by = WebDriverSubstepsBy.ByTagAndWithText("button", buttonText);
    waitFor(by, "expecting an element with tag", "button", "and text", buttonText);
    logger.debug("about to wait until element clickable");
    waitUntil(ExpectedConditions.elementToBeClickable(by));
    logger.debug("element should be clickable");
    this.webDriverContext().getCurrentElement().click();
}

From source file:com.zaizi.automation.alfresco.core.elements.Element.java

License:Open Source License

/**
 * Wait Until Element is Clickable by locator
 * @throws InterruptedException/*from   w  w  w.  j a va 2 s. c  o  m*/
 */
public static void waitUntilElementClickable(WebDriver driver, By locator) {

    WebElement myDynamicElement = (new WebDriverWait(driver, 20))
            .until(ExpectedConditions.elementToBeClickable(locator));

}

From source file:com.zaizi.sensefymobile.ios.core.elements.Element.java

License:Open Source License

/**
 * Wait Until Element is Clickable by locator
 * @throws InterruptedException/*  w ww .jav  a2  s .c  o m*/
 */
public static void waitUntilElementClickable(WebDriver driver, By locator) {

    WebElement myDynamicElement = (new WebDriverWait(driver, 20))
            .until(ExpectedConditions.elementToBeClickable(locator));

    // Span errorMessage = new Span(driver,
    // By.xpath("//body//div//div//div//span[contains(.,'Enter at least 1')]"));
    // Thread.sleep(3000);
}

From source file:com.zutubi.pulse.acceptance.SeleniumBrowser.java

License:Apache License

public void waitAndClick(By by) {
    Wait<WebDriver> wait = new WebDriverWait(webDriver, WAITFOR_TIMEOUT / 1000, 250)
            .ignoring(RuntimeException.class);
    wait.until(ExpectedConditions.elementToBeClickable(by));
    click(by);/*  w w  w .java  2  s .  co  m*/
}

From source file:de.knowwe.uitest.KnowWEUITest.java

License:Open Source License

protected WebElement waitUntilClickable(By selector) {
    return await().until(ExpectedConditions.elementToBeClickable(selector));
}

From source file:de.knowwe.uitest.UITestUtils.java

License:Open Source License

public static void logIn(WebDriver driver, String username, String password, UseCase use, WikiTemplate template)
        throws InterruptedException {
    List<WebElement> elements = null;
    if (use == UseCase.LOGIN_PAGE) {
        String idLoginElement = template == WikiTemplate.haddock ? "section-login" : "logincontent";
        elements = driver.findElements(By.id(idLoginElement));
    } else if (use == UseCase.NORMAL_PAGE) {
        if (template == WikiTemplate.haddock) {
            new WebDriverWait(driver, 20)
                    .until(ExpectedConditions.elementToBeClickable(By.className("userbox")));
            driver.findElement(By.className("userbox")).click();
            Thread.sleep(1000); //Animation
        }/*from   w  ww .jav a  2  s. c om*/
        String loginSelector = template == WikiTemplate.haddock ? "a.btn.btn-primary.btn-block.login"
                : "a.action.login";
        new WebDriverWait(driver, 20)
                .until(ExpectedConditions.elementToBeClickable(By.cssSelector(loginSelector)));
        elements = driver.findElements(By.cssSelector(loginSelector));
    }

    if (elements == null) {
        throw new NullPointerException("No Login Interface found.");
    } else if (elements.isEmpty()) {
        return; // already logged in
    }

    elements.get(0).click();
    driver.findElement(By.id("j_username")).sendKeys(username);
    driver.findElement(By.id("j_password")).sendKeys(password);
    driver.findElement(By.name("submitlogin")).click();
    String logoutSelector = template == WikiTemplate.haddock ? "a.btn.btn-default.btn-block.logout"
            : "a.action.logout";
    new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(logoutSelector)));
    new WebDriverWait(driver, 10)
            .until(ExpectedConditions.presenceOfElementLocated(By.id("edit-source-button")));
}

From source file:evs.trts.pageclass.Recruiter_UpdateCandidateInformation.java

public void updateCandidateinfo() throws InterruptedException, AWTException {

    String[][] uci = new String[4][2];
    uci[0][0] = "Devendra"; // first name
    uci[1][0] = "kUMAR"; // middle name
    uci[2][0] = "Pandy"; // last name
    uci[0][1] = "Pie"; // other source name

    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////

    firstjobcodeforUCInfo = firstjoblink.getText();
    System.out.println("first job code to update is:" + firstjobcodeforUCInfo);

    firstjoblink.click();/*from   ww  w .  ja  v  a  2  s  .  c o m*/

    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.elementToBeClickable(txt_candidateFname));

    Select gr = new Select(drpdwn_status);
    gr.selectByValue("7"); //// selected 'selected'

    txt_candidateFname.clear();
    Thread.sleep(1000);
    txt_candidateFname.sendKeys(uci[0][0]);
    txt_candidateMname.clear();
    txt_candidateMname.sendKeys(uci[1][0]);
    txt_candidateLname.clear();
    txt_candidateLname.sendKeys(uci[2][0]);
    Thread.sleep(2000);
    //try{
    calanderdatepic();
    //} catch (NotFoundException e) {System.out.println("date is not found");}
    //   Thread.sleep(1000);

    Thread.sleep(2000);
    txt_contactnum.clear();
    txt_contactnum.sendKeys("9586895621");
    Thread.sleep(1000);
    txt_emailid.clear();
    txt_emailid.sendKeys("ab@gmail.com");

    // this field is now disabled : 07 Oct 2016
    //   selectvaluefromdrpdwn(drpdwn_entity,"9");

    driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
    txt_crrntloc.clear();
    txt_crrntloc.sendKeys("Noida");
    txt_crntorganisation.clear();
    txt_crntorganisation.sendKeys("Facebook");
    Thread.sleep(2000);
    txt_noticeperiod.clear();
    txt_noticeperiod.sendKeys("30");
    txt_crntsalary.clear();
    txt_crntsalary.sendKeys("800000");
    Thread.sleep(1000);
    txt_expCTC.clear();
    txt_expCTC.sendKeys("1000000");
    selectvaluefromdrpdwn(drpdwn_skill, "45"); //Apple Technology//  other values 46,47 -> sharepoint, vba
    selectvaluefromdrpdwn(drpdwn_highestqualif, "11"); // MCA // other values 8, 10 - MBA, BCA
    selectvaluefromdrpdwn(drpdwn_specilalization, "6"); // COMPUTERS // other values 1,2- acccountancy, arts
    txt_passingyear.clear();
    txt_passingyear.sendKeys("2009");
    txt_percentage.clear();
    txt_percentage.sendKeys("88");
    txt_collegeUniv.clear();
    txt_collegeUniv.sendKeys("MDU");
    txt_ttlexpYr.clear();
    txt_ttlexpYr.sendKeys("9");
    txt_ttlexpMon.clear();
    txt_ttlexpMon.sendKeys("8");
    txt_relevINDxpYr.clear();
    txt_relevINDxpYr.sendKeys("7");
    txt_relevINDxpMon.clear();
    txt_relevINDxpMon.sendKeys("6");
    txt_relevxpYr.clear();
    txt_relevxpYr.sendKeys("5");
    Thread.sleep(500);
    txt_relevxpMo.clear();
    txt_relevxpMo.sendKeys("4");
    selectvaluefromdrpdwn(drpdown_channelsource, "5"); // SOURCER 5// other values 1, 2, 5 - Job Board, Employee Referral, Consultant
    txt_vendorcost.clear();
    txt_vendorcost.sendKeys("6000");
    Thread.sleep(1000);
    selectvaluefromdrpdwn(drpdown_sourceName, "13"); //ABC CONSULTANT 13 // rest values are 1, 3 - naukri, monster
    //   txt_sourceNameasOther.clear();
    //   txt_sourceNameasOther.sendKeys(uci[0][1]);
    selectvaluefromdrpdwn(drpdown_sourcerName, "3"); //Radhika  Acharya 3// other values 2 - debasis nandi

    Thread.sleep(1000);

    try {
        uploaadfile(browsebtn_uploadFit, "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\TestFitForm.docx");
    } catch (Exception e) {
        System.out.println("organisaton security message appear");
    }

    Thread.sleep(3000);

    try {
        uploaadfile(browsebtn_uploadresume,
                "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\TestResume.docx");
    } catch (Exception e) {
        System.out.println("organisaton security message appear");
    }

    Thread.sleep(3000);

    /*   uploaadfile(browsebtn_uploadFit, "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\TestFitForm.docx");
       Thread.sleep(1000);*/
    try {
        uploaadfile(browsebtn_purchaseorder, "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\TestPO.png");
    } catch (Exception e) {
        System.out.println("organisaton security message appear");
    }

    Thread.sleep(3000);

    try {
        uploaadfile(browsebtn_CAF, "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\TestCAF.docx");
    } catch (Exception e) {
        System.out.println("organisaton security message appear");
    }

    Thread.sleep(3000);

    selectvaluefromdrpdwn(dropdwn_idproof, "3"); // ADHAAR CARD // other values 1, 2 - passport, license
    txt_comments.clear();
    txt_comments.sendKeys("test comment");
    txt_travelcost.clear();
    txt_travelcost.sendKeys("abc");
    txt_travelcost.clear();
    txt_travelcost.sendKeys("1000");
    txt_miscost.clear();
    txt_miscost.sendKeys("fdc");
    txt_miscost.clear();
    txt_miscost.sendKeys("750");
    Thread.sleep(1000);
    uploaadfile(browsebtn_AuditZip, "C:\\TRTSautomationStuffs\\uploadedfilesforUCInfo\\trts audit test.zip");
    Thread.sleep(2000);
    btn_update.click();
    //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    Thread.sleep(4000);

    /*   Alert alert = driver.switchTo().alert();
       alert.accept();*/

    boolean noalert = true;
    while (noalert) {
        try {

            Alert alert = driver.switchTo().alert();
            noalert = false;
            String alertmsg = alert.getText();
            System.out.println("alert found and message shown is:" + alertmsg); // o/p: Request Submitted successfully
            alert.accept();
        } catch (NoAlertPresentException e) {
        }
    }

    Robot rob = new Robot();
    rob.keyPress(KeyEvent.VK_ENTER);
    rob.keyRelease(KeyEvent.VK_ENTER);

    Thread.sleep(5000);
}

From source file:FactFind.PersonalDetails.java

public static boolean CustomerPersonalDetails() {

    int MaxCustomerreached = 0;
    JSONArray CustomerInformation_Array = (JSONArray) TestExecution.JSONTestData.get("Customerinformation");
    Iterator<JSONObject> CustomerInformationArray = CustomerInformation_Array.iterator();

    String FirstCustomerFlag = "Yes";
    try {//from   www .  j a  v  a  2s.c  o m

        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.elementToBeClickable(NextButtonTopofthePage));

        while (CustomerInformationArray.hasNext()) {
            if (MaxCustomerreached >= 2) {
                break;
            }

            JSONObject CustomerInformation = CustomerInformationArray.next();

            if ((FirstCustomerFlag.equals("Yes") || CustomerInformation.get("IsApplicant").equals("Yes"))
                    && CustomerInformation.get("CustomerType").equals("Individual")) {

                if (FirstCustomerFlag.equals("Yes")) {
                    Applicant1.click();
                    Thread.sleep(3000);
                    MaxCustomerreached++;
                } else if (CustomerInformation.get("IsApplicant").equals("Yes")) {
                    Applicant2.click();
                    Thread.sleep(3000);
                    MaxCustomerreached++;
                }

                if (JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title") != null
                        && Integer.parseInt(JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title")
                                .toString()) >= 1) {
                    Title.click();
                    Helper.Keystrokeup(9);
                    Helper.Keystrokedown(Integer.parseInt(
                            JSON.GetTestData(CustomerInformation, "CustomerNames").get("Title").toString()));
                }

                if (JSON.GetTestData(CustomerInformation, "CustomerNames").get("MiddleName") != null) {
                    MiddleName.click();
                    MiddleName.clear();
                    MiddleName.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerNames").get("MiddleName")
                            .toString());
                }

                if (CustomerInformation.get("Gender") != null) {
                    if (CustomerInformation.get("Gender").equals("Male")
                            || CustomerInformation.get("Gender").equals("Female")) {
                        Gender.click();
                        Gender.sendKeys(CustomerInformation.get("Gender").toString());
                        Helper.Keystrokeenter(1);
                    } else {
                        Gender.click();
                        Gender.sendKeys("Unspecified");
                        Helper.Keystrokeenter(1);
                    }
                }

                if (CustomerInformation.get("DOB") != null) {
                    if (FirstCustomerFlag.equals("Yes")) {
                        DateOfbirth.click();
                        DateOfbirth.clear();
                        DateOfbirth.sendKeys(CustomerInformation.get("DOB").toString());
                    } else if (CustomerInformation.get("IsApplicant").equals("Yes")) {
                        DateOfbirthSpouse.click();
                        DateOfbirthSpouse.clear();
                        DateOfbirthSpouse.sendKeys(CustomerInformation.get("DOB").toString());
                    }
                }

                if (CustomerInformation.get("ResidentialStatus") != null
                        && Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) >= 1) {
                    if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 1
                            || Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 2
                            || Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 3) {
                        ResidencyStatus.click();
                        Helper.Keystrokeup(3);
                        Helper.Keystrokedown(2);
                        Helper.Keystrokeenter(1);
                    } else if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 4) {
                        ResidencyStatus.click();
                        Helper.Keystrokeup(3);
                        Helper.Keystrokedown(1);
                        Helper.Keystrokeenter(1);
                    } else if (Integer.parseInt(CustomerInformation.get("ResidentialStatus").toString()) == 5) {
                        ResidencyStatus.click();
                        Helper.Keystrokeup(3);
                        Helper.Keystrokedown(3);
                        Helper.Keystrokeenter(1);
                    }

                }

                if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails").get("Mobile") != null) {
                    Mobile.click();
                    Mobile.clear();
                    Mobile.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails")
                            .get("Mobile").toString());
                }

                if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails").get("HomePhone") != null) {
                    HomePhone.click();
                    HomePhone.clear();
                    HomePhone.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails")
                            .get("HomePhone").toString());
                }

                if (JSON.GetTestData(CustomerInformation, "CustomerContactDetails")
                        .get("BusinessPhone") != null) {
                    BusinessPhone.click();
                    BusinessPhone.clear();
                    BusinessPhone.sendKeys(JSON.GetTestData(CustomerInformation, "CustomerContactDetails")
                            .get("BusinessPhone").toString());
                }

                JSONObject FactFind = JSON.GetTestData(CustomerInformation, "FactFind");

                if (JSON.GetTestData(FactFind, "DriversLicense").get("DriversLicenceNumber") != null) {
                    DriversLicenceNumber.click();
                    DriversLicenceNumber.clear();
                    DriversLicenceNumber.sendKeys(JSON.GetTestData(FactFind, "DriversLicense")
                            .get("DriversLicenceNumber").toString());
                }

                if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenseState") != null) {
                    LicenceState.click();
                    LicenceState.sendKeys(
                            JSON.GetTestData(FactFind, "DriversLicense").get("LicenseState").toString());
                    Helper.Keystrokeenter(1);
                }

                if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued") != null) {
                    if (FirstCustomerFlag.equals("Yes")) {
                        LicenceIssued.click();
                        LicenceIssued.clear();
                        LicenceIssued.sendKeys(
                                JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued").toString());
                    } else if (CustomerInformation.get("IsApplicant").equals("Yes")) {
                        LicenceIssuedSpouse.click();
                        LicenceIssuedSpouse.clear();
                        LicenceIssuedSpouse.sendKeys(
                                JSON.GetTestData(FactFind, "DriversLicense").get("LicenceIssued").toString());
                    }
                }

                if (JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires") != null) {
                    if (FirstCustomerFlag.equals("Yes")) {
                        LicenceExpiry.click();
                        LicenceExpiry.clear();
                        LicenceExpiry.sendKeys(
                                JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires").toString());
                    } else if (CustomerInformation.get("IsApplicant").equals("Yes")) {
                        LicenceExpirySpouse.click();
                        LicenceExpirySpouse.clear();
                        LicenceExpirySpouse.sendKeys(
                                JSON.GetTestData(FactFind, "DriversLicense").get("LicenceExpires").toString());
                    }
                }

                Thread.sleep(3000);

                if (JSON.GetTestData(CustomerInformation, "CustomerDependents")
                        .get("NumberOfDependents") != null) {
                    JSONArray DependantDOBArray = (JSONArray) JSON
                            .GetTestData(CustomerInformation, "CustomerDependents").get("DependentsDOB");
                    Iterator<String> DOBArray = DependantDOBArray.iterator();
                    while (DOBArray.hasNext()) {
                        Helper.ScroolToView(driver, AddDependant);
                        AddDependant.click();
                        Thread.sleep(2000);
                        AgeofDependant.sendKeys(CalculateAge(DOBArray.next().toString()));
                        Helper.ScroolToView(driver, SaveDependent);
                        SaveDependent.click();
                    }
                }

                FirstCustomerFlag = "No";
            }

        }
        Applicant1.click();
        Thread.sleep(5000);
        Helper.ScroolToView(driver, SaveMyDetails);
        SaveMyDetails.click();
        Thread.sleep(5000);
        Helper.ScroolToView(driver, NextButtonBottomofthePage);
        NextButtonBottomofthePage.click();
        Helper.ScreenDump(TestExecution.TestExecutionFolder, "FactFindPersonalDetails");
        logger.info("FactFind Customer personal details entered successfully");
        return true;

    } catch (InterruptedException e) {
        e.printStackTrace();
        logger.error(e.toString());
        Helper.ScreenDump(TestExecution.TestExecutionFolder, "Error");
        return false;
    }

}