Example usage for org.openqa.selenium.interactions Actions moveToElement

List of usage examples for org.openqa.selenium.interactions Actions moveToElement

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions moveToElement.

Prototype

public Actions moveToElement(WebElement target) 

Source Link

Document

Moves the mouse to the middle of the element.

Usage

From source file:PageObjects.Mst_FinishesPage.java

public CCE_ExportDownloadPage pressExport() {
    WebElement element = new WebDriverWait(driver, DataItems.shortWait)
            .until(ExpectedConditions.elementToBeClickable(exportButton));

    Actions action = new Actions(driver);
    action.moveToElement(element).build().perform();

    By xlsx = By.partialLinkText("XLSX");
    WebElement xlsxBtn = new WebDriverWait(driver, DataItems.shortWait)
            .until(ExpectedConditions.elementToBeClickable(xlsx));
    xlsxBtn.click();/*from  ww w  .j a  v a2 s .c o  m*/

    return new CCE_ExportDownloadPage(driver);
}

From source file:pageobjects.ShoppingCart.java

public void deleteTemplateNumber(int number) {
    Actions actions = new Actions(driver);
    actions.moveToElement(driver.findElement(
            By.xpath(".//*[@class='del-template js-dell-template' and @data-product='" + number + "']/i")))
            .click().build().perform();//  w  ww.  j a v a2  s .co m
    driver.navigate().refresh();
}

From source file:pawl.jbehave.step.BrowserSteps.java

License:Apache License

/**
 * Action for click the web element with XY offsets from center of element.
 *
 * @param identity element identity for search
 * @param xOffset  X-offset for click//from w w w.  j  ava2s  .co  m
 * @param yOffset  Y-offset for click
 */
@When("I click '$identity' with '$xOffset' and '$yOffset' offsets")
@Alias("click '$identity' with '$xOffset' and '$yOffset' offsets")
public void clickWithOffset(final String identity, final String xOffset, final String yOffset) {
    final WebElement webElement = browser.base().find(identity);
    final Actions builder = new Actions(browser.base());
    builder.moveToElement(webElement).moveByOffset(Integer.parseInt(xOffset), Integer.parseInt(yOffset))
            // change after
            // https://code.google.com/p/selenium/issues/detail?id=6141
            // fixed
            .click().perform();
}

From source file:renascere.Renascere.java

License:Open Source License

/**
 * @Description Method that send an ACTION to a selected object
 *//* w w w . j a  v a 2  s  .com*/
public static void performAction(tAction uiAction, String sValue, WebDriver driver, WebElement wElement) {
    try {
        Actions actions = new Actions(driver);
        actions.moveToElement(wElement);
        actions.click();
        pauseExecution(Global.fTimeQSecond);
        switch (uiAction) {
        case ENTER:
            actions.sendKeys(sValue);
            actions.build().perform();
            break;
        case SELECT:
            actions.sendKeys(sValue);
            actions.build().perform();
            pauseExecution(Global.fTimeQSecond);
            actions.sendKeys(Keys.ENTER);
            actions.build().perform();
            break;
        case CHOOSE:
            actions.sendKeys(sValue);
            actions.sendKeys(Keys.ENTER);
            actions.build().perform();
            pauseExecution(Global.fTimeQSecond);
            break;
        default:
            break;
        }
        return;
    } catch (Exception e) {
        frmError("performing action " + uiAction + " with: " + sValue, e.getMessage(), severity.HIGH);
    }
}

From source file:Scenarios.CustomerSearch.AdvancedSearch_IdNum_And_OtherCriteria.java

@Test(dataProvider = "getLoginData")
public void AdvancedSearch_IdNum_And_OtherCriteria(Hashtable<String, String> tabledata) throws Exception {

    if (!(tabledata.get("Runmode").equals("Y") && tabledata.get("CustomerSearch").equals("Y"))) {
        resultFlag = "skip";
        throw new SkipException("Skipping the test");
    }//from   w  ww . j  a  v  a  2 s  .  c  o  m

    Reporter.log("Test Case Started", true);
    Thread.sleep(5000);

    try {
        logger = extent.startTest("AdvancedSearch_IdNum_And_OtherCriteria",
                "Customer Search - Advanced Search ID number and other criteria");

        Thread.sleep(5000);
        JavascriptExecutor js = (JavascriptExecutor) driver;
        LoginPage login = new LoginPage(driver);
        login.login(tabledata.get("UserName"), tabledata.get("Password"));
        logger.log(LogStatus.INFO, "Click on Login button successfully");
        String scpath, image;
        Thread.sleep(2000);

        //=================Handling Customer Facing Device================================

        Thread.sleep(5000);
        Dashboard_BifrostHostPopUp Bifrostpop = new Dashboard_BifrostHostPopUp(driver);
        logger.log(LogStatus.INFO, "PopUp window object is created successfully");
        String biforstNum = Bifrostpop.getBiforstNo();
        Robot robot = new Robot();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_T);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_T);
        Thread.sleep(3000);
        ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
        Reporter.log(tabs.size() + "", true);
        driver.switchTo().window(tabs.get(1));
        driver.get(Generic_Class.getPropertyValue("CustomerScreenPath_aut"));

        List<WebElement> biforstSystem = driver.findElements(
                By.xpath("//div[@class='scrollable-area']//span[@class='bifrost-label vertical-center']"));
        for (WebElement ele : biforstSystem) {
            if (biforstNum.equalsIgnoreCase(ele.getText().trim())) {
                Reporter.log(ele.getText() + "", true);
                ele.click();
                break;
            }
        }
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_PAGE_DOWN);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_PAGE_DOWN);
        Thread.sleep(5000);
        driver.switchTo().window(tabs.get(0));
        Thread.sleep(5000);
        driver.findElement(By.xpath(
                "//div[@id='cfsConnectionDialog']//div[@class='after-connected padding-top']//p/input[@class='psbutton-low-priority']"))
                .click();
        Thread.sleep(5000);

        //================================== PM Home Page ===============================================

        PM_Homepage pmhomepage = new PM_Homepage(driver);
        Thread.sleep(3000);

        String SiteNumber = pmhomepage.getLocation();
        logger.log(LogStatus.PASS, "location number is:" + SiteNumber);

        //Verifying PM Dash Board is displayed
        if (pmhomepage.get_WlkInCustText().trim().equalsIgnoreCase("Walk-In Customer")) {
            scpath = Generic_Class.takeScreenShotPath();
            Reporter.log(scpath, true);
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.PASS, "PM Dashboard is displayed Successfully");
            logger.log(LogStatus.INFO, "PM Dashboard is displayed Successfully", image);
        } else {

            if (resultFlag.equals("pass"))
                resultFlag = "fail";

            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.FAIL, "PM Dashboard is not displayed");
            logger.log(LogStatus.INFO, "PM Dashboard is not displayed", image);

        }
        Thread.sleep(2000);

        pmhomepage.clk_AdvSearchLnk();
        Thread.sleep(6000);
        logger.log(LogStatus.INFO, "Clicked on Advance Search link in PM home page");

        //Advance search page
        Advance_Search advSearch = new Advance_Search(driver);

        advSearch.click_StateDropdown();
        Thread.sleep(3000);
        int numberOfPixelsToDragTheScrollbarDown = 1;
        Actions dragger = new Actions(driver);
        WebElement draggablePartOfScrollbar = driver.findElement(By.xpath(
                "(//ul[@id='SearchContract_StateCode_listbox'])[2]//div[@class='ps-scrollbar-y-rail']//div[@class='ps-scrollbar-y']"));
        Thread.sleep(3000);
        List<WebElement> stateCodes = driver.findElements(
                By.xpath("(//ul[@id='SearchContract_StateCode_listbox'])[2]//li[@class='k-item']"));
        Thread.sleep(3000);

        for (int i = 1; i <= stateCodes.size(); i++) {
            WebElement ele = driver.findElement(By.xpath(
                    "((//ul[@id='SearchContract_StateCode_listbox'])[2]//li[@class='k-item'])[" + i + "]"));
            String value = ele.getText().trim();
            System.out.println(value);
            if (value.equalsIgnoreCase("CA")) {
                ele.click();
                break;
            } else if (i <= 7) {
                dragger.moveToElement(draggablePartOfScrollbar).clickAndHold()
                        .moveByOffset(0, numberOfPixelsToDragTheScrollbarDown).release().build().perform();
                numberOfPixelsToDragTheScrollbarDown += 1;
                Thread.sleep(1000);

            }

        }
        Thread.sleep(1000);

        ((JavascriptExecutor) driver).executeScript("window.scrollTo(500, 0)");
        Thread.sleep(3000);
        advSearch.clickStatusDropdown();
        Thread.sleep(2000);
        List<WebElement> statusTypes = driver.findElements(
                By.xpath("//ul[@id='SearchContract_SearchStatusID_listbox']/li[@class='k-item']"));
        Thread.sleep(2000);
        for (WebElement type : statusTypes) {
            if (type.getText().trim().equalsIgnoreCase("All")) {
                Thread.sleep(2000);
                type.click();
                break;
            }
        }
        Thread.sleep(1000);
        advSearch.enterLastName(tabledata.get("LastName"));
        Thread.sleep(1000);
        logger.log(LogStatus.INFO, "Entered Last Name is: " + tabledata.get("LastName"));
        scpath = Generic_Class.takeScreenShotPath();
        image = logger.addScreenCapture(scpath);
        logger.log(LogStatus.INFO, "img", image);
        Thread.sleep(2000);
        ((JavascriptExecutor) driver).executeScript("window.scrollBy(5000,0)");
        Thread.sleep(5000);
        ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,3000)");
        Thread.sleep(3000);
        advSearch.clickSearchbtn();
        logger.log(LogStatus.INFO, "Clicked Search button successfully");
        Thread.sleep(6000);

        try {
            String accNum = driver
                    .findElement(By.xpath("//div[@id='updateResultsPanel']//table//tbody//tr//td[11]/a"))
                    .getText();
            logger.log(LogStatus.INFO, "Account Number is : " + accNum);

            advSearch.click_accnum_Grid();
            logger.log(LogStatus.INFO, "Clicked on Account Number");
            Thread.sleep(4000);

            Acc_CustomerInfoPage custInfo = new Acc_CustomerInfoPage(driver);

            //String getAcc = custInfo.getAccNum();
            String cusName = driver.findElement(By.xpath("//h1[@class='customer-name bold']")).getText().trim();
            logger.log(LogStatus.INFO, "Customer Name is : " + cusName);

            Thread.sleep(2000);

            ((JavascriptExecutor) driver).executeScript("window.scrollBy(2000,0)");
            Thread.sleep(2000);

            custInfo.click_EditAccountDetails();
            Thread.sleep(5000);

            Cust_EditAccountDetailsPage editAcc = new Cust_EditAccountDetailsPage(driver);
            editAcc.clickCustInfoRadioBtn();
            logger.log(LogStatus.INFO, "Selected Customer Info radio button");
            Thread.sleep(2000);
            editAcc.clickYesRadioBtn();
            logger.log(LogStatus.INFO, "Selected Yes radio button");
            Thread.sleep(1000);
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "Image", image);
            Thread.sleep(1000);
            editAcc.clickLaunchBtn();
            Thread.sleep(5000);

            logger.log(LogStatus.PASS, "Navigated to Customer Information Screen");
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "Image", image);

            Cust_CustomerInfoPage info = new Cust_CustomerInfoPage(driver);
            info.clk_selectIdentificationType();
            Thread.sleep(2000);

            List<WebElement> iden = driver.findElements(By.xpath(
                    "//ul[@id='IndividualInformationModel_ContactIdentification_IdentificationTypeID_listbox']/li"));
            Thread.sleep(2000);
            for (WebElement type : iden) {
                if (type.getText().trim().equalsIgnoreCase("Passport")) {
                    Thread.sleep(2000);
                    type.click();
                    break;
                }
            }
            Thread.sleep(1000);

            info.clk_Country();
            Thread.sleep(2000);

            int numberOfPixelsToDragTheScrollbarDow = 1;
            Actions dragger1 = new Actions(driver);
            WebElement draggablePartOfScrollbar1 = driver.findElement(By.xpath(
                    "//ul[@id='IndividualInformationModel_ContactIdentification_CountryTypeID_listbox']/div[@class='ps-scrollbar-y-rail']//div[@class='ps-scrollbar-y']"));
            Thread.sleep(3000);
            List<WebElement> listCountry1 = driver.findElements(By.xpath(
                    "//ul[@id='IndividualInformationModel_ContactIdentification_CountryTypeID_listbox']/li"));
            Thread.sleep(3000);

            for (int i = 1; i <= listCountry1.size(); i++) {
                WebElement ele = driver.findElement(By.xpath(
                        "//ul[@id='IndividualInformationModel_ContactIdentification_CountryTypeID_listbox']/li["
                                + i + "]"));
                String value = ele.getText().trim();
                System.out.println(value);
                if (value.equalsIgnoreCase("India")) {
                    ele.click();
                    break;
                } else if (i <= 12) {
                    dragger1.moveToElement(draggablePartOfScrollbar1).clickAndHold()
                            .moveByOffset(0, numberOfPixelsToDragTheScrollbarDow).release().build().perform();
                    numberOfPixelsToDragTheScrollbarDow += 1;
                    Thread.sleep(1000);

                }

            }
            Thread.sleep(1000);
            info.enterLicenseNumber(tabledata.get("PassportNumber"));
            logger.log(LogStatus.INFO, "Entered Passport ID Number : " + tabledata.get("PassportNumber"));
            Thread.sleep(3000);
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "Image", image);

            js = (JavascriptExecutor) driver;
            js.executeScript("window.scrollBy(0,3000)", "");

            info.clk_verifyButton();
            Thread.sleep(5000);

            try {
                boolean error = driver
                        .findElement(By.xpath("//div[contains(text(),'Email Address is required')]"))
                        .isDisplayed();
                if (error) {
                    info.clickNoEmailCheckBox();
                    Thread.sleep(2000);

                    js = (JavascriptExecutor) driver;
                    js.executeScript("window.scrollBy(0,3000)", "");

                    info.clk_verifyButton();
                    Thread.sleep(7000);
                }

            } catch (Exception e) {

            }

            info.clk_ConfirmBtn();
            Thread.sleep(5000);

            driver.switchTo().window(tabs.get(1));
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_PAGE_DOWN);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyRelease(KeyEvent.VK_PAGE_DOWN);

            WebElement signature = driver
                    .findElement(By.xpath("//div[@class='signature-area']/canvas[@class='signature-pad']"));
            Actions actionBuilder = new Actions(driver);
            Action drawAction = actionBuilder.moveToElement(signature, 660, 96).click().clickAndHold(signature)
                    .moveByOffset(120, 120).moveByOffset(60, 70).moveByOffset(-140, -140).release(signature)
                    .build();
            drawAction.perform();
            Thread.sleep(5000);
            logger.log(LogStatus.INFO, "Got signature from Customer");
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "img", image);
            driver.findElement(By.xpath("//button[text()='Accept']")).click();
            Thread.sleep(5000);
            driver.switchTo().window(tabs.get(0));
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_PAGE_DOWN);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            robot.keyRelease(KeyEvent.VK_PAGE_DOWN);

            info.clk_ApproveBtn();
            Thread.sleep(2000);
            logger.log(LogStatus.PASS, "Customer approved the changes from CFS");
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "Image", image);

            info.clk_SaveBtn();
            Thread.sleep(5000);

            EmergencyContact_EmployeeIdPage empId = new EmergencyContact_EmployeeIdPage(driver);
            empId.enter_EmployeeId(tabledata.get("UserName"));
            Thread.sleep(3000);
            empId.click_ContinueBtn();
            Thread.sleep(20000);

            try {
                driver.findElement(By.xpath("//a[contains(text(),'OK')]")).click();
                Thread.sleep(6000);
            } catch (Exception e) {

            }

            Cust_AccDetailsPage accDet = new Cust_AccDetailsPage(driver);
            accDet.click_BackToDashboard();
            Thread.sleep(8000);

            pmhomepage.clk_AdvSearchLnk();
            Thread.sleep(6000);
            logger.log(LogStatus.INFO, "Clicked on Advance Search link in PM home page");

            //Advance search page

            advSearch.click_StateDropdown();
            Thread.sleep(3000);
            int numberOfPixelsToDragTheScrollbarDownn = 1;
            Actions dragger2 = new Actions(driver);
            WebElement draggablePartOfScrollbar2 = driver.findElement(By.xpath(
                    "(//ul[@id='SearchContract_StateCode_listbox'])[2]//div[@class='ps-scrollbar-y-rail']//div[@class='ps-scrollbar-y']"));
            Thread.sleep(3000);
            List<WebElement> stateCodes2 = driver.findElements(
                    By.xpath("(//ul[@id='SearchContract_StateCode_listbox'])[2]//li[@class='k-item']"));
            Thread.sleep(3000);

            for (int i = 1; i <= stateCodes2.size(); i++) {
                WebElement ele = driver.findElement(By.xpath(
                        "((//ul[@id='SearchContract_StateCode_listbox'])[2]//li[@class='k-item'])[" + i + "]"));
                String value = ele.getText().trim();
                System.out.println(value);
                if (value.equalsIgnoreCase("CA")) {
                    ele.click();
                    break;
                } else if (i <= 7) {
                    dragger2.moveToElement(draggablePartOfScrollbar2).clickAndHold()
                            .moveByOffset(0, numberOfPixelsToDragTheScrollbarDownn).release().build().perform();
                    numberOfPixelsToDragTheScrollbarDownn += 1;
                    Thread.sleep(1000);

                }

            }
            Thread.sleep(1000);

            ((JavascriptExecutor) driver).executeScript("window.scrollTo(500, 0)");
            Thread.sleep(3000);
            advSearch.clickStatusDropdown();
            Thread.sleep(2000);
            List<WebElement> statusTypes2 = driver.findElements(
                    By.xpath("//ul[@id='SearchContract_SearchStatusID_listbox']/li[@class='k-item']"));
            Thread.sleep(2000);
            for (WebElement type : statusTypes2) {
                if (type.getText().trim().equalsIgnoreCase("All")) {
                    Thread.sleep(2000);
                    type.click();
                    break;
                }
            }
            Thread.sleep(1000);
            advSearch.enterLastName(tabledata.get("LastName"));
            logger.log(LogStatus.INFO, "Entered Last Name is: " + tabledata.get("LastName"));
            Thread.sleep(2000);
            ((JavascriptExecutor) driver).executeScript("window.scrollBy(5000,0)");
            Thread.sleep(4000);
            advSearch.enterIdNum(tabledata.get("PassportNumber"));
            logger.log(LogStatus.INFO, "Entered Passport id : " + tabledata.get("PassportNumber"));
            Thread.sleep(2000);
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "img", image);
            Thread.sleep(2000);

            ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,3000)");
            Thread.sleep(3000);
            advSearch.clickSearchbtn();
            logger.log(LogStatus.INFO, "Clicked Search button successfully");
            Thread.sleep(6000);

            String accNum1 = driver
                    .findElement(By.xpath("//div[@id='updateResultsPanel']//table//tbody//tr//td[11]/a"))
                    .getText();

            advSearch.click_accnum_Grid();
            logger.log(LogStatus.INFO, "Clicked on Account Number");
            Thread.sleep(6000);

            if (accNum.equals(accNum1)) {
                scpath = Generic_Class.takeScreenShotPath();
                Reporter.log(scpath, true);
                image = logger.addScreenCapture(scpath);
                logger.log(LogStatus.PASS,
                        "Account Number : " + accNum + " is matched successfully " + accNum1);
                logger.log(LogStatus.INFO, "img", image);
            } else {

                if (resultFlag.equals("pass"))
                    resultFlag = "fail";

                scpath = Generic_Class.takeScreenShotPath();
                image = logger.addScreenCapture(scpath);
                logger.log(LogStatus.FAIL,
                        "Account Number : " + accNum + " is not matched successfully " + accNum1);
                logger.log(LogStatus.INFO, "img", image);

            }

            String cusName1 = driver.findElement(By.xpath("//h1[@class='customer-name bold']")).getText()
                    .trim();
            if (cusName.equals(cusName1)) {
                scpath = Generic_Class.takeScreenShotPath();
                Reporter.log(scpath, true);
                image = logger.addScreenCapture(scpath);
                logger.log(LogStatus.PASS,
                        "Customer Name : " + cusName + " is matched successfully " + cusName1);
                logger.log(LogStatus.INFO, "img", image);
            } else {

                if (resultFlag.equals("pass"))
                    resultFlag = "fail";

                scpath = Generic_Class.takeScreenShotPath();
                image = logger.addScreenCapture(scpath);
                logger.log(LogStatus.FAIL,
                        "Customer Name : " + cusName + " is not matched successfully " + cusName1);
                logger.log(LogStatus.INFO, "img", image);

            }

        } catch (Exception e) {
            logger.log(LogStatus.INFO, "No records found for the searched criteria");
            Thread.sleep(1000);
            scpath = Generic_Class.takeScreenShotPath();
            image = logger.addScreenCapture(scpath);
            logger.log(LogStatus.INFO, "img", image);

        }

    } catch (Exception ex) {
        ex.printStackTrace();
        resultFlag = "fail";
        logger.log(LogStatus.FAIL, "Test script failed due to the exception " + ex);
    }

}

From source file:se.nackademin.seleniumide.assignment.TestProductCategoriesMenu.java

public void navigateMenuProductCategories(WebElement element, String identifier, WebDriver driver,
        String assertionTitle) {//from   w w  w  .  j  a va2s  .c om
    Actions builder = new Actions(driver);
    element = driver.findElement(By.cssSelector("#menu-item-33"));
    builder.moveToElement(element).perform();
    driver.findElement(By.cssSelector(identifier)).click();
    Assert.assertEquals(assertionTitle, driver.getTitle());
}

From source file:server.system.scripts.ImportLicense.java

public boolean importLicence(WebDriver objWebDriver, String licFilePath, Logger accessLog)
        throws InterruptedException, IOException {
    boolean result = false;

    // Navigate to Licenses tab:
    try {//  w  w  w  .j  a  v  a 2  s.  c  o  m
        CommonFunctions.navigateToTab(MenuNavigation.ImportLicense, objWebDriver, accessLog, null);
        // Check if the license is already imported or not, if not - import
        // the license:
        if (!objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                .getAttribute("title").toString().equalsIgnoreCase("License Active")) // Status
        // strings
        // for
        // validation
        // -
        // 'No
        // License'
        // 'License
        // Active'
        {
            // Click on Import License
            CommonFunctions.doClickAndSwitchToIFrame(objWebDriver, accessLog,
                    By.xpath(MenuNavigation.System.ImportLicense.btnImportLicense),
                    By.id(MenuNavigation.System.ImportLicense.frmIDImportLicense));
            Thread.sleep(2000);

            // find and Click on Browse button
            WebElement btnBrowse = objWebDriver
                    .findElement(By.xpath(MenuNavigation.System.ImportLicense.btnBrowse));
            Actions builder = new Actions(objWebDriver);
            builder.moveToElement(btnBrowse).perform();
            builder.doubleClick().perform();

            // Call AutoIT exe
            String[] commands = { Driver.mConfigFile.getLibFolder() + File.separator + "import_license.exe",
                    "Choose File to Upload", licFilePath };

            try {
                Process proc;
                proc = Runtime.getRuntime().exec(commands);
                // Wait for AutoIT script to end successfully
                InputStream is = proc.getInputStream();
                int retCode = 0;
                while (retCode != -1) {
                    retCode = is.read();
                    blnStatus = true;
                }
                is.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                accessLog.error("Caught exception while executing the AutoIT script");
                e1.printStackTrace();
                result = false;
            }

            // Click on Import button
            CommonFunctions.doClickAndWait(objWebDriver,
                    By.xpath(MenuNavigation.System.ImportLicense.btnImport),
                    By.xpath(MenuNavigation.System.ImportLicense.btnImportLicense), accessLog);
            Thread.sleep(1000);

            // Take screen shot
            if (blnStatus) {
                // validate that license has been imported successfully
                if (objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                        .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")
                        && objWebDriver
                                .findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                                .getAttribute("title").toString().equalsIgnoreCase("License Active")) {
                    accessLog.info(
                            "The license file : has been imported successfully and below are the details about active license");
                    accessLog
                            .info("Windows Server : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedWS))
                                            .getText().toString());
                    accessLog
                            .info("Windows WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedWW))
                                            .getText().toString());
                    accessLog
                            .info("Linux Server : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedLS))
                                            .getText().toString());
                    accessLog
                            .info("Linux WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedLW))
                                            .getText().toString());
                    accessLog
                            .info("MAC WorkStation : Status - "
                                    + objWebDriver
                                            .findElement(By
                                                    .xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                                            .getAttribute("title").toString()
                                    + ", Agents Allowed - "
                                    + objWebDriver
                                            .findElement(By.xpath(
                                                    MenuNavigation.System.ImportLicense.spnAgntAllowedMW))
                                            .getText().toString());

                }
                // Take Screenshot
                CommonFunctions.takeScreenshot(objWebDriver, strCurScriptName, "license_imported", accessLog);
                result = true;
            }
        } else if (objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                .getAttribute("title").toString().equalsIgnoreCase("License Active")) {
            accessLog.info("the license is already imported, here is the summary :: ");
            accessLog.info("Windows Server : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWS))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedWS))
                            .getText().toString());
            accessLog.info("Windows WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusWW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedWW))
                            .getText().toString());
            accessLog.info("Linux Server : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLS))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedLS))
                            .getText().toString());
            accessLog.info("Linux WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusLW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedLW))
                            .getText().toString());
            accessLog.info("MAC WorkStation : Status - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnLicStatusMW))
                            .getAttribute("title").toString()
                    + ", Agents Allowed - "
                    + objWebDriver.findElement(By.xpath(MenuNavigation.System.ImportLicense.spnAgntAllowedMW))
                            .getText().toString());
            result = true;
        }
    } catch (Exception e) {
        accessLog.error("Caught Exception while Importing the license ");
        accessLog.error(e.getMessage());
        e.printStackTrace();
        result = false;
    }
    return result;
}

From source file:suppliers.pageobject.PageLogin.java

public void clickLoginButton() {
    Actions act = new Actions(driver);
    act.moveToElement(loginbtn);
    act.click().perform();
}

From source file:swift.selenium.WebHelper.java

License:Open Source License

@SuppressWarnings("incomplete-switch")
public static String doAction(String imageType, String controlType, String controlId, String controlName,
        String ctrlValue, String logicalName, String action, WebElement webElement, Boolean Results,
        HSSFSheet strucSheet, HSSFSheet valSheet, int rowIndex, int rowcount, String rowNo, String colNo)
        throws Exception {
    List<WebElement> WebElementList = null;
    String currentValue = null;//from w w w .j ava2 s  .c o  m
    //HSSFSheet uniqueNumberSheet =null;
    String uniqueNumber = "";
    WebVerification.isFromVerification = false;
    //HashMap<String ,Object> uniqueValuesHashMap = null;
    //HSSFRow uniqueRow = null;
    ControlTypeEnum controlTypeEnum = ControlTypeEnum.valueOf(controlType);
    ControlTypeEnum actionName = ControlTypeEnum.valueOf(action.toString());
    if (controlType.contains("Robot") && !isIntialized) {
        robot = new Robot();
        isIntialized = true;
    }

    if (action.toString().equalsIgnoreCase("I") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("Read") || action.toString().equalsIgnoreCase("Write")
            || action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("NC")
            || action.toString().equalsIgnoreCase("T") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("F") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("VA") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("O") || action.toString().equalsIgnoreCase("CP")
            || action.toString().equalsIgnoreCase("GV") || action.toString().equalsIgnoreCase("LV")
            || action.toString().equalsIgnoreCase("GB") || action.toString().equalsIgnoreCase("Get")
            || action.toString().equalsIgnoreCase("Post")) {
        try {
            switch (controlTypeEnum) {

            case WebEdit:
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    webElement.clear();
                    webElement.sendKeys(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    if (!ctrlValue.equalsIgnoreCase("null")) {
                        webElement.clear();
                        webElement.sendKeys(ctrlValue);
                    } else {
                        webElement.clear();
                    }
                    break;
                case T:
                    if (!ctrlValue.equalsIgnoreCase("null")) {
                        webElement.clear();
                        webElement.sendKeys(ctrlValue);
                        ((DeviceActionShortcuts) Automation.driver).hideKeyboard();
                    } else {
                        webElement.clear();
                    }
                    break;
                case V:
                    currentValue = webElement.getText();
                    break;
                }
                break;

            case WebButton:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        webElement.click();
                    }
                    break;
                case NC:
                    webElement.click();
                    break;
                case V:
                    if (webElement.isDisplayed()) {
                        if (webElement.isEnabled() == true)
                            currentValue = "True";
                        else
                            currentValue = "False";
                    }
                }
                break;

            case WebElement:
                switch (actionName) {

                case I:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    webElement.click();
                    break;

                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    webElement.clear();
                    webElement.sendKeys(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case V:
                    if (WebVerification.isFromVerification == true) {
                        currentValue = webElement.getText();
                        break;
                    }
                    boolean textPresent = false;
                    String ObservedText = webElement.getText();
                    if (StringUtils.isBlank(ObservedText)) {
                        ObservedText = webElement.getAttribute("value");
                    }

                    textPresent = ObservedText.contains(ctrlValue);
                    if (textPresent == false)
                        currentValue = Boolean.toString(textPresent);
                    else
                        currentValue = ctrlValue;
                    break;

                case T:
                    Point p = ((Locatable) webElement).getCoordinates().onPage();
                    ((MobileDriver) Automation.driver).tap(1, p.getX(), p.getY(), 1);
                    break;
                }
                break;

            case JSScript:
                ((JavascriptExecutor) Automation.driver).executeScript(controlName, ctrlValue);
                break;

            case Wait:
                Thread.sleep(Integer.parseInt(controlName) * 1000);
                break;

            case CheckBox:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        webElement.click();
                    }
                    break;
                case NC:
                    webElement.click();
                    break;
                }
                break;

            case Radio:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        if (!webElement.isSelected()) {
                            webElement.click();
                        }
                    }
                    break;
                case NC:
                    if (!webElement.isSelected()) {
                        webElement.click();
                    }
                    break;
                case V:
                    if (webElement.isSelected()) {
                        currentValue = webElement.getAttribute(controlName.toString());
                    }
                    break;
                case F:
                    if (webElement != null) {
                        currentValue = "Y";
                    }
                    break;
                }
                break;

            case WebLink:
                //case CloseWindow://added this Case to bypass page loading after clicking the event
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    WebElementList = getElementsByType(controlId, controlName, controlType, imageType,
                            uniqueNumber);
                    webElement = GetControlByIndex("", WebElementList, controlId, controlName, controlType,
                            uniqueNumber);
                    webElement.click();
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    if (controlId.equalsIgnoreCase("LinkValue")) {
                        webElement.click();
                    } else {
                        if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                            webElement.click();
                        }
                    }
                    break;
                case NC:
                    webElement.click();
                    break;
                }
                break;

            case CloseWindow: //TM-09/09/2015: This case is written to help in closing any specific windows
                switch (actionName) {
                case I: //This case helps in closing a specific window on the basis on the given title            
                    Set<String> handlers = null;
                    handlers = Automation.driver.getWindowHandles();
                    for (String handler : handlers) {
                        Automation.driver = Automation.driver.switchTo().window(handler);

                        //TM-19/01/2015: Changed following comparison from equalsIgnoreCase to contains
                        if (Automation.driver.getTitle().contains(ctrlValue)) {
                            System.out.println("Closing required window :-" + Automation.driver.getTitle());
                            Automation.driver.close();
                            break;
                        }
                    }
                    break;
                case NC://This case helps in closing the window with current focus
                    Automation.driver.close();
                    break;
                }
                break;
            case WaitForJS:
                waitForCondition();
                break;

            case ListBox:
            case WebList:
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    new Select(webElement).selectByVisibleText(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    ExpectedCondition<Boolean> isTextPresent = CommonExpectedConditions
                            .textToBePresentInElement(webElement, ctrlValue);
                    if (isTextPresent != null) {
                        if (webElement != null) {
                            new Select(webElement).selectByVisibleText(ctrlValue);
                        }
                    }
                    break;
                case V:
                    if (!ctrlValue.contains(",")) {
                        currentValue = new Select(webElement).getFirstSelectedOption().getText();
                        if (currentValue.isEmpty()) {
                            currentValue = new Select(webElement).getFirstSelectedOption()
                                    .getAttribute("value");
                        }

                        break;
                    } else {
                        currentValue = new String();
                        List<WebElement> currentValues = new ArrayList<WebElement>();
                        currentValues = new Select(webElement).getOptions();

                        for (int j = 0; j < currentValues.size(); j++) {
                            if (j + 1 == currentValues.size())
                                currentValue = currentValue.concat(currentValues.get(j).getText());
                            else {
                                currentValue = currentValue.concat(currentValues.get(j).getText() + ",");
                            }
                        }
                        break;
                    }
                }
                break;

            //New code for AJAX Dropdown with dojo
            case AjaxWebList:
                switch (actionName) {
                case I:
                    webElement.click();
                    break;
                case VA:
                    Thread.sleep(20000);
                    currentValue = new String();
                    List<WebElement> currentValues = new ArrayList<WebElement>();
                    currentValues = Automation.driver.findElements(By.xpath(controlName));

                    for (int j = 0; j < currentValues.size(); j++) {
                        if (j + 1 == currentValues.size())
                            currentValue = currentValue.concat(currentValues.get(j).getText());
                        else {
                            currentValue = currentValue.concat(currentValues.get(j).getText() + ",");
                        }
                    }
                    break;
                }
                break;
            case IFrame:
                Automation.driver = Automation.driver.switchTo().frame(controlName);
                break;

            case Browser:
                Set<String> handlers = null;
                handlers = Automation.driver.getWindowHandles();
                for (String handler : handlers) {
                    Automation.driver = Automation.driver.switchTo().window(handler);
                    if (Automation.driver.getTitle().contains(controlName)) {
                        System.out.println("Focus on window with title: " + Automation.driver.getTitle());
                        break;
                    }
                }
                break;

            case BrowserControl:
                Set<String> winHandles = Automation.driver.getWindowHandles();
                boolean controlfound = false;
                winHandles = Automation.driver.getWindowHandles();
                for (String handler : winHandles) {
                    Automation.driver = Automation.driver.switchTo().window(handler);

                    try {
                        Automation.driver.findElement(By.xpath(controlName));
                        System.out.println("Focus on window with Control: " + controlName);
                        controlfound = true;
                        break;

                    } catch (Exception e) {
                        // TODO: handle exception
                    }
                }

                if (!controlfound)
                    System.out.println("Unable to find control with : " + controlName);
                break;

            case BrowserType:
                switch (actionName) {
                case I:
                    if (StringUtils.isNotBlank(ctrlValue)) {
                        Automation.browser = Automation.configHashMap.get("BROWSERTYPE").toString();
                        if (StringUtils.equalsIgnoreCase("none", Automation.browser)) {
                            Automation.browser = ctrlValue.toString();
                            Automation.browserType = Automation.browserTypeEnum.valueOf(Automation.browser);
                            Automation.setUp();
                            wait = new WebDriverWait(Automation.driver,
                                    Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));
                            //Thread.sleep(5000);
                        }
                    }
                    break;
                case NC:
                    if (StringUtils.isNotBlank(controlName)) {
                        Automation.browser = Automation.configHashMap.get("BROWSERTYPE").toString();
                        if (StringUtils.equalsIgnoreCase("none", Automation.browser)) {
                            Automation.browser = controlName.toString();
                            Automation.browserType = Automation.browserTypeEnum.valueOf(Automation.browser);
                            Automation.setUp();
                            wait = new WebDriverWait(Automation.driver,
                                    Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));
                            //Thread.sleep(5000);
                        }
                    }
                    break;
                }
                break;
            case BrowserAuth:
                final String details[] = ctrlValue.split(",");
                Runnable thread2 = new Runnable() {
                    public void run() {
                        try {
                            smartRobot = new SmartRobot();
                            Thread.sleep(5000);
                            smartRobot.type(details[0].toString());// Enter username      
                            Thread.sleep(2000);
                            smartRobot.pressTab();// Click Keyboard Tab                              
                            smartRobot.type(details[1].toString());// Enter password      
                            Thread.sleep(2000);
                            smartRobot.pressEnter();// Click Enter button
                            Thread.sleep(5000);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                };
                Thread thr2 = new Thread(thread2);
                thr2.start();
                break;

            case URL:
                final String url = ctrlValue;
                if (!StringUtils.isBlank(ctrlValue)) {
                    if (Automation.browser.equals("InternetExplorer")) {
                        Automation.driver.navigate().to(url);
                        Thread.sleep(5000);
                    } else {
                        Runnable thread1 = new Runnable() {
                            public void run() {
                                try {
                                    Automation.driver.navigate().to(url);
                                    Thread.sleep(5000);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                        };
                        Thread thr1 = new Thread(thread1);
                        thr1.start();
                    }
                }
                break;

            case Menu:
                webElement.click();
                break;

            case Alert:
                switch (actionName) {
                case V:
                    Alert alert = wait.until(ExpectedConditions.alertIsPresent());
                    if (alert != null) {
                        Automation.driver.switchTo().alert();
                        currentValue = alert.getText();
                        System.out.println(currentValue);
                        alert.accept();
                    }
                    break;
                }
                break;

            case WebImage:
                webElement.sendKeys(Keys.TAB);
                webElement.click();
                Thread.sleep(5000);
                for (int Seconds = 0; Seconds <= Integer
                        .parseInt(Automation.configHashMap.get("TIMEOUT").toString()); Seconds++) {
                    if (!((Automation.driver.getWindowHandles().size()) > 1)) {
                        webElement.click();
                        Thread.sleep(5000);
                    } else {
                        break;
                    }
                }
                break;

            case ActionClick:
                Actions builderClick = new Actions(Automation.driver);
                Action clickAction = builderClick.moveToElement(webElement).clickAndHold().release().build();
                clickAction.perform();
                break;

            case ActionDoubleClick:
                Actions builderdoubleClick = new Actions(Automation.driver);
                builderdoubleClick.doubleClick(webElement).perform();//TM-27/01/2015 :- commented following code and used this code for simultaneous clicks
                //Action doubleClickAction = builderdoubleClick.moveToElement(webElement).click().build();
                //doubleClickAction.perform();
                //doubleClickAction.perform();                  
                break;

            case ActionClickandEsc:
                Actions clickandEsc = new Actions(Automation.driver);
                Action clickEscAction = clickandEsc.moveToElement(webElement).click()
                        .sendKeys(Keys.ENTER, Keys.ESCAPE).build();
                clickEscAction.perform();
                break;

            case ActionMouseOver:
                Actions builderMouserOver = new Actions(Automation.driver);
                Action mouseOverAction = builderMouserOver.moveToElement(webElement).build();
                mouseOverAction.perform();
                break;

            case Calendar:
                //   Thread.sleep(5000);
                Boolean isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed();
                System.out.println(isCalendarDisplayed);
                if (isCalendarDisplayed == true) {
                    String[] dtMthYr = ctrlValue.split("/");
                    WebElement Year = WaitTool.waitForElement(Automation.driver, By.name("year"),
                            Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.name("year"));
                    while (!Year.getAttribute("value").equalsIgnoreCase(dtMthYr[2])) {
                        if (Integer.parseInt(Year.getAttribute("value")) > Integer.parseInt(dtMthYr[2])) {
                            WebElement yearButton = WaitTool.waitForElement(Automation.driver, By.id("button1"),
                                    Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("button1"));
                            yearButton.click();
                        } else if (Integer.parseInt(Year.getAttribute("value")) < Integer
                                .parseInt(dtMthYr[2])) {
                            WebElement yearButton = WaitTool.waitForElement(Automation.driver, By.id("Button5"),
                                    Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button5"));
                            yearButton.click();
                        }
                    }
                    Select date = new Select(WaitTool.waitForElement(Automation.driver, By.name("month"),
                            Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString())));
                    month = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYr[1]));
                    date.selectByVisibleText(month);
                    WebElement Day = WaitTool.waitForElement(Automation.driver, By.id("Button6"),
                            Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button6"));
                    int day = 6;
                    while (Day.getAttribute("value") != null) {
                        Day = WaitTool.waitForElement(Automation.driver, By.id("Button" + day),
                                Integer.parseInt(Automation.configHashMap.get("TIMEOUT").toString()));//Automation.driver.findElement(By.id("Button"+day));
                        if (Day.getAttribute("value").toString().equalsIgnoreCase(dtMthYr[0])) {
                            Day.click();
                            break;
                        }
                        day++;
                    }
                } else {
                    System.out.println("Calendar not Diplayed");
                }
                //Automation.selenium.click(controlName);
                break;

            case CalendarNew:
                isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed();
                System.out.println(isCalendarDisplayed);
                if (isCalendarDisplayed == true) {

                    String[] dtMthYr = ctrlValue.split("/");
                    Thread.sleep(2000);
                    //String[] CurrentDate = dtFormat.format(frmDate).split("/");
                    WebElement Monthyear = Automation.driver.findElement(By.xpath("//table/thead/tr/td[2]"));
                    String Monthyear1 = Monthyear.getText();
                    String[] Monthyear2 = Monthyear1.split(",");
                    Monthyear2[1] = Monthyear2[1].trim();

                    month = CalendarSnippet.getMonthForString(Monthyear2[0]);

                    while (!Monthyear2[1].equalsIgnoreCase(dtMthYr[2])) {
                        if (Integer.parseInt(Monthyear2[1]) > Integer.parseInt(dtMthYr[2])) {
                            WebElement yearButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            yearButton.click();
                            Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) - 1);
                        } else if (Integer.parseInt(Monthyear2[1]) < Integer.parseInt(dtMthYr[2])) {
                            WebElement yearButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            yearButton.click();
                            Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) + 1);
                        }
                    }

                    while (!month.equalsIgnoreCase(dtMthYr[1])) {
                        if (Integer.parseInt(month) > Integer.parseInt(dtMthYr[1])) {
                            WebElement monthButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            monthButton.click();
                            if (Integer.parseInt(month) < 11) {
                                month = "0" + Integer.toString(Integer.parseInt(month) - 1);
                            } else {
                                month = Integer.toString(Integer.parseInt(month) - 1);
                            }

                        } else if (Integer.parseInt(month) < Integer.parseInt(dtMthYr[1])) {
                            WebElement monthButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            monthButton.click();
                            if (Integer.parseInt(month) < 9) {
                                month = "0" + Integer.toString(Integer.parseInt(month) + 1);
                            } else {
                                month = Integer.toString(Integer.parseInt(month) + 1);
                            }
                        }
                    }

                    WebElement dateButton = Automation.driver
                            .findElement(By.cssSelector("td.day:contains('" + dtMthYr[0] + "')"));
                    System.out.println(dateButton);
                    dateButton.click();

                } else {
                    System.out.println("Calendar not Diplayed");
                }
                break;

            case CalendarIPF:
                String[] dtMthYr = ctrlValue.split("/");
                Thread.sleep(2000);
                String year = dtMthYr[2];
                String monthNum = dtMthYr[1];
                String day = dtMthYr[0];

                //Xpath for Year, mMnth & Days
                String xpathYear = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-years']";
                String xpathMonth = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-months']";
                String xpathDay = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-days']";

                //Selecting year in 3 steps
                Automation.driver.findElement(By.xpath(xpathDay + "/table/thead/tr[1]/th[2]")).click();
                Automation.driver.findElement(By.xpath(xpathMonth + "/table/thead/tr/th[2]")).click();
                Automation.driver
                        .findElement(By.xpath(xpathYear
                                + "/table/tbody/tr/td/span[@class='year'][contains(text()," + year + ")]"))
                        .click();

                //Selecting month in 1 step   
                Automation.driver
                        .findElement(By.xpath(xpathMonth + "/table/tbody/tr/td/span[" + monthNum + "]"))
                        .click();

                //Selecting day in 1 step
                Automation.driver
                        .findElement(By.xpath(
                                xpathDay + "/table/tbody/tr/td[@class='day'][contains(text()," + day + ")]"))
                        .click();

            case CalendarEBP:
                String[] dtMthYrEBP = ctrlValue.split("/");
                Thread.sleep(500);
                String yearEBP = dtMthYrEBP[2];
                String monthNumEBP = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYrEBP[1]))
                        .substring(0, 3);
                String dayEBP = dtMthYrEBP[0];

                //common path used for most of the elements
                String pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div";

                //following is to click the title once to reach the year page
                wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div")))
                        .click();
                //check if 'Dec' is visibly clickable after refreshing
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(
                        pathToVisibleCalendar + "/div/div/table/tbody/tr/td/div[contains(text(), 'Dec')]")));
                Thread.sleep(5000);
                //following is to click the title once again to reach the year page
                wait.until(ExpectedConditions.elementToBeClickable(
                        (By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div"))))
                        .click();
                //common path used for most of the elements while selection of year, month and date
                pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div/div/div/table/tbody/tr/td";
                Thread.sleep(2000);
                //each of the following line selects the year, month and date
                wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath(pathToVisibleCalendar + "/div[contains(text()," + yearEBP + ")]"))).click();
                Thread.sleep(2000);
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar
                        + "/div[@class='ajax__calendar_month'][contains(text(),'" + monthNumEBP + "')]")))
                        .click();
                Thread.sleep(2000);
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar
                        + "/div[@class='ajax__calendar_day'][contains(text()," + dayEBP + ")]"))).click();

                break;

            /**Code for window popups**/
            case Window:
                switch (actionName) {
                case O:
                    String parentHandle = Automation.driver.getWindowHandle();
                    for (String winHandle : Automation.driver.getWindowHandles()) {
                        Automation.driver.switchTo().window(winHandle);
                        if (Automation.driver.getTitle().contains(controlName)) {
                            ((JavascriptExecutor) Automation.driver)
                                    .executeScript("window.onbeforeunload = function(e){};");//By Tripti: 16/02/2015
                            Automation.driver.close();
                        } else {
                            parentHandle = winHandle;
                        }

                    }
                    Automation.driver.switchTo().window(parentHandle);
                    break;
                }
                break;

            case WebTable:
                switch (actionName) {
                case Read:
                    ReadFromExcel(ctrlValue);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case NC:
                    WebElement table = webElement;
                    List<WebElement> tableRows = table.findElements(By.tagName("tr"));
                    int tableRowIndex = 0;
                    //int tableColumnIndex = 0;
                    boolean matchFound = false;
                    for (WebElement tableRow : tableRows) {
                        tableRowIndex += 1;
                        List<WebElement> tableColumns = tableRow.findElements(By.tagName("td"));
                        if (tableColumns.size() > 0) {
                            for (WebElement tableColumn : tableColumns)
                                if (tableColumn.getText().equals(ctrlValue)) {
                                    matchFound = true;
                                    System.out.println(tableRowIndex);
                                    List<Object> elementProperties = getPropertiesOfWebElement(
                                            tableColumns.get(Integer.parseInt(colNo)), imageType);
                                    controlName = elementProperties.get(0).toString();
                                    if (controlName.equals("")) {
                                        controlName = elementProperties.get(1).toString();
                                    }
                                    controlType = elementProperties.get(2).toString();
                                    webElement = (WebElement) elementProperties.get(3);
                                    doAction(imageType, controlType, controlId, controlName, ctrlValue,
                                            logicalName, action, webElement, Results, strucSheet, valSheet,
                                            tableRowIndex, rowcount, rowNo, colNo);
                                    break;
                                }
                            if (matchFound) {
                                break;
                            }
                        }

                    }
                    break;
                case V:
                    WriteToDetailResults(ctrlValue, "", logicalName);
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    break;

                case GB:
                    WebVerification.GroupBy = ctrlValue;
                    break;
                }
                break;

            case Robot:

                if (controlName.equalsIgnoreCase("SetFilePath")) {
                    StringSelection stringSelection = new StringSelection(ctrlValue);
                    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);

                    robot.delay(5000);
                    robot.keyPress(KeyEvent.VK_CONTROL);
                    robot.keyPress(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_CONTROL);

                } else if (controlName.equalsIgnoreCase("Type")) {
                    robot.keyPress(KeyEvent.VK_M);
                    robot.keyRelease(KeyEvent.VK_TAB);
                } else if (controlName.equalsIgnoreCase("TAB")) {
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                } else if (controlName.equalsIgnoreCase("SPACE")) {
                    robot.keyPress(KeyEvent.VK_SPACE);
                    robot.keyRelease(KeyEvent.VK_SPACE);
                } else if (controlName.equalsIgnoreCase("ENTER")) {
                    robot.keyPress(KeyEvent.VK_ENTER);
                    robot.keyRelease(KeyEvent.VK_ENTER);
                }

                break;

            case DB:
                switch (actionName) {
                case Write:
                    ResultSet rs = JDBCConnection.establishDBConn("", ctrlValue);
                    rs.next();
                    ctrlValue = String.valueOf(rs.getLong("COL_1"));
                    rs.close();
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                }
                break;
            //Kinjal 9/6/2015 Added for DB Approach   
            case DBV:
                switch (actionName) {
                case CP:
                    currentValue = webElement.getText();
                    if (StringUtils.isBlank(currentValue)) {
                        currentValue = webElement.getAttribute("value");
                    }
                    ctrlValue = JDBCConnection.getFirstColumnName(ctrlValue);
                    System.out.println("Database value fetched from DB is " + ctrlValue);
                    break;

                case V:

                    List<WebElement> rowElements = WebHelper.getElementsByType(controlId, controlName, "", "",
                            "");
                    if (rowElements != null) {
                        currentValue = Integer.toString(rowElements.size());
                    } else {
                        currentValue = "0";
                    }

                    ctrlValue = JDBCConnection.getFirstColumnName(ctrlValue);
                    break;
                }
                break;

            case WaitForEC:
                wait.until(CommonExpectedConditions.elementToBeClickable(webElement));
                break;

            case SikuliType:
                sikuliScreen.type(controlName, ctrlValue);
                break;

            case SikuliButton:
                sikuliScreen.click(controlName);
                System.out.println("Done");
                break;

            case Date:
                Calendar cal = new GregorianCalendar();
                int i = cal.get(Calendar.DAY_OF_MONTH);
                if (i >= 31) {
                    i = i - 10;
                }
                break;

            case FileUpload:
                webElement.sendKeys(ctrlValue);
                break;

            case ScrollTo:
                //Locatable element = (Locatable) webElement; //TM:04/03/2015-commented as incorrect
                //Point p= element.getCoordinates().onScreen();//TM:04/03/2015-commented as incorrect
                Point p = webElement.getLocation();//TM:04/03/2015-New correct code
                System.out.println("X,Y co-ordinates of textbox is:- " + p);//TM:04/03/2015-New correct code
                JavascriptExecutor js = (JavascriptExecutor) Automation.driver; //TM:04/03/2015-New correct code
                js.executeScript("window.scrollTo(" + p.getX() + "," + (p.getY() + 150) + ");");
                break;

            case SwitchContext:
                Thread.sleep(3000);
                Set<String> contexts = ((AppiumDriver) Automation.driver).getContextHandles();
                for (String s : contexts) {
                    System.out.println("Count of contexts : " + contexts.size());
                    System.out.println("Context Name : " + s);
                    if (s.contains(ctrlValue)) {
                        System.out.println("Mobile Web View found");
                        ((AppiumDriver) Automation.driver).context(s);
                        break;
                    }
                }
                Thread.sleep(2000);

                break;
            case SwipeDown:
                //((AppiumDriver)(Automation.driver)).swipe(0, 0, 0, 1500, 2000);
                ((AppiumDriver) (Automation.driver)).scrollTo(ctrlValue);
                break;

            case CaptureScreen:
                Date toDate = new Date();
                TransactionMapping.report.setFromDate(Automation.dtFormat.format(frmDate));
                TransactionMapping.report
                        .setStrIteration(Automation.configHashMap.get("CYCLENUMBER").toString());
                TransactionMapping.report.setStrTestcaseId(MainController.controllerTestCaseID.toString());
                TransactionMapping.report.setStrGroupName(MainController.controllerGroupName.toString());
                TransactionMapping.report
                        .setStrTrasactionType(MainController.controllerTransactionType.toString());
                TransactionMapping.report.setStrTestDescription(MainController.testDesciption);
                TransactionMapping.report.setStrMessage(
                        "Screenshot of Test Case Id:" + MainController.controllerTestCaseID.toString()
                                + " & Transaction Type:" + MainController.controllerTransactionType.toString());
                TransactionMapping.report.setToDate(Automation.dtFormat.format(toDate));
                saveScreenShot(TransactionMapping.report, logicalName);
                break;
            case WebService:
                switch (actionName) {
                case I:
                    if (logicalName.equalsIgnoreCase("WSDL_URL"))
                        wsdl_url = ctrlValue;
                    else if (logicalName.equalsIgnoreCase("REQUEST_URL"))
                        request_url = ctrlValue;
                    else if (logicalName.equalsIgnoreCase("REQUEST_XML"))
                        request_xml = ctrlValue;
                    break;

                case T:
                    WebService.callWebService();
                    break;

                case V:
                    currentValue = WebService.getXMLTagValue(controlName);
                    break;
                }
                break;

            case WebService_REST:
                switch (actionName) {
                case I:
                    if (logicalName.equalsIgnoreCase("REQUEST_URL"))
                        request_url = ctrlValue;
                    else if (logicalName.equalsIgnoreCase("REQUEST_XML")) {
                        request_xml = ctrlValue;
                    }
                    break;
                case Get:
                    WebService.callRESTWebService("Get", controlId);
                    break;

                case Post:
                    WebService.callRESTWebService("Post", controlId);
                    break;

                case V:
                    if (controlId.equalsIgnoreCase("JSON")) {
                        currentValue = WebService.getJSONTagValue(controlName);
                    } else {
                        currentValue = WebService.getXMLTagValue(controlName);
                    }
                    break;
                }
                break;

            case JSONResp:
                switch (actionName) {
                case I:
                    if (logicalName.equalsIgnoreCase("JSON_URL")) {
                        response_url = controlName;
                        response_fileName = ctrlValue;
                        WebService.downloadAndStoreJson(response_url, response_fileName);
                    }
                    break;
                }
                break;

            case DonutChart:
                switch (actionName) {
                case GV:

                    DonutChart donut = new DonutChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(), donut.getDonutColumnNames(),
                            donut.getDonutChartData());
                    break;

                case LV:

                    DonutChart donutLegend = new DonutChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(),
                            donutLegend.getDonutLegendColumnNames(), donutLegend.getDonutLegendData());
                    break;
                }
                break;

            case BarChart:
                switch (actionName) {
                case GV:

                    String[] series = ctrlValue.split("!");
                    List<String> seriesList = Arrays.asList(series);
                    BarChart barChart = new BarChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(), barChart.getColumnNames(),
                            barChart.getChartData(seriesList));
                    break;

                case LV:

                    BarChart barchartLegend = new BarChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(),
                            barchartLegend.getLegendColumnNames(), barchartLegend.getLegendData());
                    break;
                }
                break;
            case BasicLineChart:
                switch (actionName) {
                case GV:

                    BasicLineChart lineChart = new BasicLineChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(), lineChart.getColumnNames(),
                            lineChart.getChartData());
                    break;

                case LV:

                    BasicLineChart linechartLegend = new BasicLineChart(Automation.driver, webElement);
                    WebVerification.verifyTabularData(testcaseID.toString(),
                            MainController.controllerTransactionType.toString(),
                            linechartLegend.getLegendColumnNames(), linechartLegend.getLegendData());
                    break;
                }
                break;
            default:
                System.out.println("U r in Default");
                break;
            }

        } catch (WebDriverException we) {
            throw new Exception("Error Occurred from Do Action " + controlName + we.getMessage());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }
    //TM-02/02/2015: Radio button found ("F") & AJAX control ("VA")
    if ((action.toString().equalsIgnoreCase("V") || action.toString().equalsIgnoreCase("CP")
            || action.toString().equalsIgnoreCase("F") || action.toString().equalsIgnoreCase("VA"))
            && !ctrlValue.equalsIgnoreCase("")) {
        if (Results == true) {
            TransactionMapping.report = WriteToDetailResults(ctrlValue, currentValue, logicalName);
        }
    }

    return currentValue;

}

From source file:SwiftSeleniumWeb.WebHelper.java

License:Open Source License

/**
 * This class performs the reuired action on an element
 * /*from   w w w . j a v  a 2  s.co m*/
 * @param imageType
 * @param controlType
 * @param controlId
 * @param controlName
 * @param ctrlValue
 * @param logicalName
 * @param action
 * @param webElement
 * @param Results
 * @param strucSheet
 * @param valSheet
 * @param rowIndex
 * @param rowcount
 * @param rowNo
 * @param colNo
 * @return
 * @throws Exception
 */
@SuppressWarnings("incomplete-switch")
public static String doAction(String imageType, String controlType, String controlId, String controlName,
        String ctrlValue, String logicalName, String action, WebElement webElement, Boolean Results,
        HSSFSheet strucSheet, HSSFSheet valSheet, int rowIndex, int rowcount, String rowNo, String colNo)
        throws Exception {
    List<WebElement> WebElementList = null;
    String currentValue = null;
    String uniqueNumber = "";
    ControlTypeEnum controlTypeEnum = ControlTypeEnum.valueOf(controlType);
    ControlTypeEnum actionName = ControlTypeEnum.valueOf(action.toString());
    if (controlType.contains("Robot") && !isIntialized) {
        robot = new Robot();
        isIntialized = true;
    }

    if (action.toString().equalsIgnoreCase("I") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("Read") || action.toString().equalsIgnoreCase("Write")
            || action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("")
            || action.toString().equalsIgnoreCase("NC")
            || action.toString().equalsIgnoreCase("T") && !ctrlValue.equalsIgnoreCase("")) {
        try {
            switch (controlTypeEnum) {

            case WebEdit:
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    webElement.clear();
                    webElement.sendKeys(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    if (!ctrlValue.equalsIgnoreCase("null")) {
                        webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                        webElement.clear();
                        webElement.sendKeys(ctrlValue);
                    } else {
                        webElement.clear();
                    }
                    break;
                case V:
                    currentValue = webElement.getText();
                    break;
                }
                break;

            case WebButton:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                        webElement.click();
                    }
                    break;
                case NC:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    webElement.click();
                    break;
                case V:
                    if (webElement.isDisplayed()) {
                        if (webElement.isEnabled() == true)
                            currentValue = "True";
                        else
                            currentValue = "False";
                    }
                }
                break;

            case WebElement:
                switch (actionName) {
                case I:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    webElement.click();
                    break;

                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    webElement.clear();
                    webElement.sendKeys(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case V:
                    boolean textPresent = false;
                    textPresent = webElement.getText().contains(ctrlValue);
                    if (textPresent == false)
                        currentValue = webElement.getText();
                    else
                        currentValue = ctrlValue;
                    break;
                }
                break;

            case JSScript:
                ((JavascriptExecutor) Automation.driver).executeScript(controlName, ctrlValue);
                break;

            case Wait:
                Thread.sleep(Integer.parseInt(controlName) * 1000);
                break;

            case CheckBox:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                        webElement.click();
                    }
                    break;
                case NC:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    webElement.click();
                    break;
                }
                break;

            case Radio:
                switch (actionName) {
                case I:
                    if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                        webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                        if (!webElement.isSelected()) {
                            webElement.click();
                        }
                    }
                    break;
                case NC:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    if (!webElement.isSelected()) {
                        webElement.click();
                    }
                    break;
                case V:
                    if (webElement.isSelected()) {
                        currentValue = webElement.getAttribute(controlName.toString());
                    }
                    break;
                }
                break;

            case WebLink:
            case CloseWindow://added this Case to bypass page loading after clicking the event
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    WebElementList = getElementsByType(controlId, controlName, controlType, imageType,
                            uniqueNumber);
                    webElement = GetControlByIndex("", WebElementList, controlId, controlName, controlType,
                            uniqueNumber);
                    webElement.click();
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    if (controlId.equalsIgnoreCase("LinkValue")) {
                        webElement.click();
                    } else {
                        if (ctrlValue.equalsIgnoreCase("Y") || ctrlValue.equalsIgnoreCase("Yes")) {
                            webElement.click();
                        }
                    }
                    break;
                case NC:
                    webElement.click();
                    break;
                }
                break;

            case WaitForJS:
                waitForCondition();
                break;

            case ListBox:
            case WebList:
                switch (actionName) {
                case Read:
                    uniqueNumber = ReadFromExcel(ctrlValue);
                    new Select(webElement).selectByVisibleText(uniqueNumber);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case I:
                    webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                    ExpectedCondition<Boolean> isTextPresent = CommonExpectedConditions
                            .textToBePresentInElement(webElement, ctrlValue);
                    if (isTextPresent != null) {
                        if (webElement != null) {
                            new Select(webElement).selectByVisibleText(ctrlValue);
                        }
                    }
                    break;
                case V:
                    currentValue = new Select(webElement).getFirstSelectedOption().getText();
                    if (currentValue.isEmpty()) {
                        currentValue = new Select(webElement).getFirstSelectedOption().getAttribute("value");
                    }
                    break;
                }
                break;

            case IFrame:
                Automation.driver = Automation.driver.switchTo().frame(controlName);
                break;

            case Browser:
                //Thread.sleep(3000); //DS:Check if required
                Set<String> handlers = Automation.driver.getWindowHandles();
                handlers = Automation.driver.getWindowHandles();
                for (String handler : handlers) {
                    Automation.driver = Automation.driver.switchTo().window(handler);
                    if (Automation.driver.getTitle().equalsIgnoreCase(controlName)) {
                        System.out.println("Focus on window with title: " + Automation.driver.getTitle());
                        break;
                    }
                }
                break;

            case URL:
                switch (actionName) {
                case I:
                    Automation.driver.navigate().to(ctrlValue);
                    break;
                case NC:
                    break;
                }
                break;

            case Menu:
                webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                webElement.click();
                break;

            case Alert:
                switch (actionName) {
                case V:
                    Alert alert = Automation.driver.switchTo().alert();
                    if (alert != null) {
                        currentValue = alert.getText();
                        System.out.println(currentValue);
                        alert.accept();
                    }
                    break;
                }
                break;

            case WebImage:
                webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                webElement.click();
                Thread.sleep(5000);
                for (int Seconds = 0; Seconds <= Integer
                        .parseInt(Automation.configHashMap.get("TIMEOUT").toString()); Seconds++) {
                    if (!((Automation.driver.getWindowHandles().size()) > 1)) {
                        webElement.click();
                        Thread.sleep(5000);
                    } else {
                        break;
                    }
                }
                break;

            case ActionClick:
                webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                Actions builderClick = new Actions(Automation.driver);
                Action clickAction = builderClick.moveToElement(webElement).clickAndHold().release().build();
                clickAction.perform();
                break;

            case ActionDoubleClick:
                webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                Actions builderdoubleClick = new Actions(Automation.driver);
                Action doubleClickAction = builderdoubleClick.moveToElement(webElement).click().build();
                doubleClickAction.perform();
                doubleClickAction.perform();
                break;

            case ActionClickandEsc:
                webElement = wait.until(ExpectedConditions.elementToBeClickable(webElement));
                Actions clickandEsc = new Actions(Automation.driver);
                Action clickEscAction = clickandEsc.moveToElement(webElement).click()
                        .sendKeys(Keys.ENTER, Keys.ESCAPE).build();
                clickEscAction.perform();
                break;

            case ActionMouseOver:
                Actions builderMouserOver = new Actions(Automation.driver);
                Action mouseOverAction = builderMouserOver.moveToElement(webElement).build();
                mouseOverAction.perform();
                break;

            case CalendarNew:
                Boolean isCalendarDisplayed = Automation.driver.switchTo().activeElement().isDisplayed();
                System.out.println(isCalendarDisplayed);
                if (isCalendarDisplayed == true) {

                    String[] dtMthYr = ctrlValue.split("/");
                    Thread.sleep(2000);
                    //String[] CurrentDate = dtFormat.format(frmDate).split("/");
                    WebElement Monthyear = Automation.driver.findElement(By.xpath("//table/thead/tr/td[2]"));
                    String Monthyear1 = Monthyear.getText();
                    String[] Monthyear2 = Monthyear1.split(",");
                    Monthyear2[1] = Monthyear2[1].trim();

                    month = CalendarSnippet.getMonthForString(Monthyear2[0]);

                    while (!Monthyear2[1].equalsIgnoreCase(dtMthYr[2])) {
                        if (Integer.parseInt(Monthyear2[1]) > Integer.parseInt(dtMthYr[2])) {
                            WebElement yearButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            yearButton.click();
                            Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) - 1);
                        } else if (Integer.parseInt(Monthyear2[1]) < Integer.parseInt(dtMthYr[2])) {
                            WebElement yearButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            yearButton.click();
                            Monthyear2[1] = Integer.toString(Integer.parseInt(Monthyear2[1]) + 1);
                        }
                    }

                    while (!month.equalsIgnoreCase(dtMthYr[1])) {
                        if (Integer.parseInt(month) > Integer.parseInt(dtMthYr[1])) {
                            WebElement monthButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            monthButton.click();
                            if (Integer.parseInt(month) < 11) {
                                month = "0" + Integer.toString(Integer.parseInt(month) - 1);
                            } else {
                                month = Integer.toString(Integer.parseInt(month) - 1);
                            }

                        } else if (Integer.parseInt(month) < Integer.parseInt(dtMthYr[1])) {
                            WebElement monthButton = Automation.driver
                                    .findElement(By.cssSelector("td:contains('')"));
                            monthButton.click();
                            if (Integer.parseInt(month) < 9) {
                                month = "0" + Integer.toString(Integer.parseInt(month) + 1);
                            } else {
                                month = Integer.toString(Integer.parseInt(month) + 1);
                            }
                        }
                    }

                    WebElement dateButton = Automation.driver
                            .findElement(By.cssSelector("td.day:contains('" + dtMthYr[0] + "')"));
                    System.out.println(dateButton);
                    dateButton.click();

                } else {
                    System.out.println("Calendar not Diplayed");
                }
                break;

            case CalendarIPF:
                String[] dtMthYr = ctrlValue.split("/");
                Thread.sleep(2000);
                String year = dtMthYr[2];
                String monthNum = dtMthYr[1];
                String day = dtMthYr[0];

                //Xpath for Year, mMnth & Days
                String xpathYear = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-years']";
                String xpathMonth = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-months']";
                String xpathDay = "//div[@class='datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom']/div[@class='datepicker-days']";

                //Selecting year in 3 steps
                Automation.driver.findElement(By.xpath(xpathDay + "/table/thead/tr[1]/th[2]")).click();
                Automation.driver.findElement(By.xpath(xpathMonth + "/table/thead/tr/th[2]")).click();
                Automation.driver
                        .findElement(By.xpath(xpathYear
                                + "/table/tbody/tr/td/span[@class='year'][contains(text()," + year + ")]"))
                        .click();

                //Selecting month in 1 step   
                Automation.driver
                        .findElement(By.xpath(xpathMonth + "/table/tbody/tr/td/span[" + monthNum + "]"))
                        .click();

                //Selecting day in 1 step
                Automation.driver
                        .findElement(By.xpath(
                                xpathDay + "/table/tbody/tr/td[@class='day'][contains(text()," + day + ")]"))
                        .click();

            case CalendarEBP:
                String[] dtMthYrEBP = ctrlValue.split("/");
                Thread.sleep(2000);
                String yearEBP = dtMthYrEBP[2];
                String monthNumEBP = CalendarSnippet.getMonthForInt(Integer.parseInt(dtMthYrEBP[1]))
                        .substring(0, 3);
                String dayEBP = dtMthYrEBP[0];

                //common path used for most of the elements
                String pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div";

                //following is to click the title once to reach the year page
                wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath(pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div")))
                        .click();
                //check if 'Dec' is visibly clickable after refreshing
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(
                        pathToVisibleCalendar + "/div/div/table/tbody/tr/td/div[contains(text(), 'Dec')]")));
                //following is to click the title once again to reach the year page
                Automation.driver
                        .findElement(By.xpath(
                                pathToVisibleCalendar + "/div[@class='ajax__calendar_header']/div[3]/div"))
                        .click();

                //common path used for most of the elements while selection of year, month and date
                pathToVisibleCalendar = "//div[@class='ajax__calendar'][contains(@style, 'visibility: visible;')]/div/div/div/table/tbody/tr/td";

                //each of the following line selects the year, month and date
                wait.until(ExpectedConditions.elementToBeClickable(
                        By.xpath(pathToVisibleCalendar + "/div[contains(text()," + yearEBP + ")]"))).click();
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar
                        + "/div[@class='ajax__calendar_month'][contains(text(),'" + monthNumEBP + "')]")))
                        .click();
                wait.until(ExpectedConditions.elementToBeClickable(By.xpath(pathToVisibleCalendar
                        + "/div[@class='ajax__calendar_day'][contains(text()," + dayEBP + ")]"))).click();

                break;

            /**Code for window popups**/
            case Window:
                switch (actionName) {
                case O:
                    String parentHandle = Automation.driver.getWindowHandle();
                    for (String winHandle : Automation.driver.getWindowHandles()) {
                        Automation.driver.switchTo().window(winHandle);
                        if (Automation.driver.getTitle().equalsIgnoreCase(controlName)) {
                            Automation.driver.close();
                        }
                    }
                    Automation.driver.switchTo().window(parentHandle);
                    break;
                }
                break;

            case WebTable:
                switch (actionName) {
                case Read:
                    ReadFromExcel(ctrlValue);
                    break;
                case Write:
                    writeToExcel(ctrlValue, webElement, controlId, controlType, controlName, rowNo, colNo);
                    break;
                case NC:
                    WebElement table = webElement;
                    List<WebElement> tableRows = table.findElements(By.tagName("tr"));
                    int tableRowIndex = 0;
                    //int tableColumnIndex = 0;
                    boolean matchFound = false;
                    for (WebElement tableRow : tableRows) {
                        tableRowIndex += 1;
                        List<WebElement> tableColumns = tableRow.findElements(By.tagName("td"));
                        if (tableColumns.size() > 0) {
                            for (WebElement tableColumn : tableColumns)
                                if (tableColumn.getText().equals(ctrlValue)) {
                                    matchFound = true;
                                    System.out.println(tableRowIndex);
                                    List<Object> elementProperties = getPropertiesOfWebElement(
                                            tableColumns.get(Integer.parseInt(colNo)), imageType);
                                    controlName = elementProperties.get(0).toString();
                                    if (controlName.equals("")) {
                                        controlName = elementProperties.get(1).toString();
                                    }
                                    controlType = elementProperties.get(2).toString();
                                    webElement = (WebElement) elementProperties.get(3);
                                    doAction(imageType, controlType, controlId, controlName, ctrlValue,
                                            logicalName, action, webElement, Results, strucSheet, valSheet,
                                            tableRowIndex, rowcount, rowNo, colNo);
                                    break;
                                }
                            if (matchFound) {
                                break;
                            }
                        }

                    }
                    break;
                case V:
                    WriteToDetailResults(ctrlValue, "", logicalName);
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    break;
                }
                break;

            case Robot:
                if (controlName.equalsIgnoreCase("SetFilePath")) {
                    StringSelection stringSelection = new StringSelection(ctrlValue);
                    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);
                    robot.delay(1000);
                    robot.keyPress(KeyEvent.VK_CONTROL);
                    robot.keyPress(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_CONTROL);

                } else if (controlName.equalsIgnoreCase("TAB")) {
                    robot.keyPress(KeyEvent.VK_TAB);
                    robot.keyRelease(KeyEvent.VK_TAB);
                } else if (controlName.equalsIgnoreCase("SPACE")) {
                    robot.keyPress(KeyEvent.VK_SPACE);
                    robot.keyRelease(KeyEvent.VK_SPACE);
                } else if (controlName.equalsIgnoreCase("ENTER")) {
                    robot.keyPress(KeyEvent.VK_ENTER);
                    robot.keyRelease(KeyEvent.VK_ENTER);
                }
                break;

            case WaitForEC:
                wait.until(CommonExpectedConditions.elementToBeClickable(webElement));
                break;

            case SikuliType:
                sikuliScreen.type(controlName, ctrlValue);
                break;

            case SikuliButton:
                sikuliScreen.click(controlName);
                System.out.println("Done");
                break;

            case Date:
                Calendar cal = new GregorianCalendar();
                int i = cal.get(Calendar.DAY_OF_MONTH);
                if (i >= 31) {
                    i = i - 10;
                }
                break;

            case FileUpload:
                webElement.sendKeys(ctrlValue);
                break;

            case ScrollTo:
                Locatable element = (Locatable) webElement;
                Point p = element.getCoordinates().onScreen();
                JavascriptExecutor js = (JavascriptExecutor) Automation.driver;
                js.executeScript("window.scrollTo(" + p.getX() + "," + (p.getY() + 150) + ");");
                break;

            default:
                System.out.println("U r in Default");
                break;
            }
        } catch (WebDriverException we) {
            throw new Exception("Error Occurred from Do Action " + controlName + we.getMessage());
        } catch (Exception e) {
            throw new Exception(e.getMessage());
        }
    }

    if (action.toString().equalsIgnoreCase("V") && !ctrlValue.equalsIgnoreCase("")) {
        if (Results == true) {
            SwiftSeleniumWeb.WebDriver.report = WriteToDetailResults(ctrlValue, currentValue, logicalName);
        }
    }

    return currentValue;

}