Example usage for org.openqa.selenium By xpath

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

Introduction

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

Prototype

public static By xpath(String xpathExpression) 

Source Link

Usage

From source file:com.cengage.mindtap.keywords.InsiteAppPageActions.java

public void uploadFile() {
    waitTOSync();/*ww w .j  a  v  a2  s  .  c  o m*/
    waitTOSync();
    waitTOSync();
    waitTOSync();

    driver.switchTo().frame(driver.findElement(By.xpath("//div[@id='upload-modal']//iframe")));
    element("submissionTitle").sendKeys("test");
    wait.hardWait(5);
    element("filepath").click();

    //element("filepath").sendKeys("C:\\Users\\chandanjyot\\Desktop\\Task_22July.txt");

    //  sendKeys("C:\\Users\\chandanjyot\\Desktop\\Task_22July.txt");
    //        windowHandle=driver.getWindowHandle();
    //        ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
    //        //driver.switchTo().alert();
    //        //alert.sendKeys("test 123");
    //        System.out.println(tabs2.size());
    //        driver.switchTo().window(tabs2.get(1));
    //        //ReportMsg.info("tab switched");
    //        //changeWindow(1);
    //        waitTOSync();
    //        String Url = driver.getTitle();
    //        System.out.println(Url);
    // switchToFrame("fallbackframe");
    //        switchToFrame("fallbackframe");
    //        element("submissionTitle").sendKeys("test");
    //        element("filePath").sendKeys("C:\\Users\\Mann\\Desktop\\Order Confirmation _ Amway Site.pdf");
}

From source file:com.cengage.mindtap.keywords.InsiteAppPageActions.java

public void createDistinctPeerAssignment() {
    //long time = System.currentTimeMillis();

    Assert.assertTrue(element("CreateAssignmentButton").isDisplayed(),
            "Create New Assignment Button is not present");
    element("CreateAssignmentButton").click();
    waitTOSync();/*from   w  w w . j  a  v a2  s  . c o m*/
    Select dropdown = new Select(driver.findElement(By.xpath("//select[@id='paperAssignments']")));
    dropdown.selectByIndex(0);
    element("Continue_PeerButton").click();
    waitTOSync();
    waitTOSync();
    waitForElementPresent("peer_AssignTab");
    // Assert.assertTrue(element("peer_AssignTab").isDisplayed(), "Tabs are not appearing in peermark page");
    waitTOSync();
    element("Done_PeerButton").click();
    //waitForElementPresent("save_btn");

}

From source file:com.cengage.mindtap.keywords.KalturaAppPageActions.java

void editDistinctActivity(String title) {

    String bookClassName = driver.findElement(By.xpath(
            "//h3[contains(@class,'lpn_name') and contains(.,'" + title + "')]/parent::*/parent::*/parent::*"))
            .getAttribute("class");
    ((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('" + bookClassName
            + "')[0].getElementsByClassName('nb_edit')[0].style.display = 'block';");
    driver.findElement(By.xpath("//h3[contains(@class,'lpn_name') and contains(.,'" + title
            + "')]/parent::*/parent::*/parent::*//div[@class='nb_edit' and contains(@style,'block')]//a[@title='Edit']/img"))
            .click();/*from   w w w.jav  a 2s .  c  om*/
}

From source file:com.cengage.mindtap.keywords.KalturaAppPageActions.java

void inputDistinctActivityTitleAndDescription(String title, String description) {

    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date date = new Date();
    System.out.println(dateFormat.format(date));

    String timestamp;/*w w w .  jav a2 s .  c  o  m*/
    timestamp = dateFormat.format(date);

    String input = title + " " + timestamp.toString();
    String desc = description + " " + timestamp.toString();
    try {

        element("title_inputField").click();
        element("title_inputField").clear();
        element("title_inputField").sendKeys(input);
        element("description_inputField").clear();
        element("description_inputField").sendKeys(desc);
    } catch (Exception e) {
        //To avoid stale element exception
        driver.findElement(By.xpath("//input[contains(@class,'required validates')]")).click();
        driver.findElement(By.xpath("//input[contains(@class,'required validates')]")).clear();
        driver.findElement(By.xpath("//input[contains(@class,'required validates')]")).sendKeys(input);
    }
    selectOrder();
    element("save_btn1").click();
    closeAnnouncement();

    //waitForElementDisplayed(driver.findElement(By.xpath("//div[contains(@class,'lpn_activity')]//h3[@class='lpn_name' and contains(.,'"+title+"')]")))
}

From source file:com.cengage.mindtap.keywords.KalturaAppPageActions.java

/**
* Delete distinct activity.//ww  w.  j  a v a2  s  .  c  o m
*
* @param title the title
*/
public void deleteDistinctActivity(String title) {

    //  List<WebElement> nb_list = driver.findElements(By.xpath("//div[@id='lpn_workspace' and contains(@style,'block')]//div[contains(@class,'lpn_node lpn_activity')]//h3[contains(@class,'lpn_name') and contains(.,'"+title+"')]")); 
    List<WebElement> nb_list = driver.findElements(By.xpath(
            "//div[contains(@class,'lpn_node lpn_activity')]//h3[contains(@class,'lpn_name') and contains(.,'"
                    + title + "')]"));
    int len = nb_list.size();
    while (len > 0) {
        waitTOSync();
        String bookClassName = driver.findElement(By.xpath("(//h3[contains(@class,'lpn_name') and contains(.,'"
                + title + "')]/parent::*/parent::*/parent::*)[" + len + "]")).getAttribute("class").toString();
        ((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('" + bookClassName
                + "')[0].getElementsByClassName('nb_edit')[0].style.display = 'block';");
        System.out.println("Script executed.....................................");

        clickOnElementUsingActionBuilder(
                driver.findElement(By.xpath("//h3[contains(@class,'lpn_name') and contains(.,'" + title
                        + "')]/parent::*/parent::*/parent::*//div[@class='nb_edit' and contains(@style,'block')]//a[@title='Delete']/img")));
        //driver.findElement(By.xpath("//h3[contains(@class,'lpn_name') and contains(.,'"+title+"')]/parent::*/parent::*/parent::*//a[@title='Delete']")).click()
        System.out.println("Clicked .....................................");
        acceptAlertWindow();
        System.out.println("Alert come......................................");

        len--;
        if (len == 0)
            break;
    }
}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

public boolean searchMasterBook(String bookName) {

    Select dropdown = new Select(driver.findElement(By.xpath("//select[@class='numresults']")));
    dropdown.selectByVisibleText("10 Rows");
    waitTOSync();/*www .  j  a v a  2 s. co  m*/
    int countMaster = 0;
    for (WebElement searchBookTitle : elements("searchBookResults_list")) {
        if (searchBookTitle.getText().equals(bookName)) {
            //System.out.println("Book Title:" + searchBookTitle.getText());
            //System.out.println(searchBookTitle.getText());
            //searchBookTitle.click();
            countMaster = countMaster + 1;
        }
    }

    if (countMaster == 20) {
        return true;

    } else {
        return false;
    }

}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

public void clickBookModifyOption(String searchTerm, String option, String role) {
    int optionNumber = 0;
    int optionsCount = 0;
    int i = 0;//www.  java 2 s.com
    optionNumber = findoptionNumber(option, role);

    List<WebElement> masterBook_list = driver
            .findElements(By.xpath("//li[contains(@class, 'item  master admin_models_master')]"));
    for (WebElement masterBook : masterBook_list) {
        System.out.println("In masterBook ");
        //if (masterBook.findElement(By.xpath("(//div/div[@class='listText']/a)[2]")).getText().equals(searchTerm)  || masterBook.findElement(By.xpath("//div/div[@class='listText']/a")).getText().equals(searchTerm)) {
        if (masterBook.findElement(By.xpath("//div/div[@class='listText']/a")).getText().equals(searchTerm)) {
            System.out.println("In IF ");
            String bookClassName = masterBook.getAttribute("class");
            System.out.println("optionCount : " + optionNumber);
            executeJavascript("document.getElementsByClassName('" + bookClassName
                    + "')[0].getElementsByTagName('a')[" + optionNumber + "].style.display = 'block';");
            wait.hardWait(2);
            for (WebElement option1 : elements("masterBookControlOptions_list", option)) {
                try {
                    System.out.println("optionCount : " + optionNumber);
                    System.out.println(option1.getAttribute("alt"));
                    System.out.println(option);
                    if (option1.isDisplayed() && option1.getAttribute("alt").equals(option)) {
                        System.out.println("optionCount : " + optionNumber);
                        executeJavascript("document.getElementsByClassName('" + bookClassName
                                + "')[0].getElementsByTagName('a')[" + optionNumber
                                + "].style.display = 'block';");
                        hover(option1);
                        clickOnElementUsingActionBuilder(option1);

                        if (option.equals("Delete")) {
                            handleAlert();
                            wait.hardWait(20);
                        }
                        break;
                    }
                } catch (ElementNotFoundException e) {
                    System.out.println("Options are not available to Click");
                }
            }
            break;
        }
    }
}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

public void ProvisionAppsButton(String title, String appRegistryOption1) {
    try {//from   www .j a va 2  s.c  om
        String bookClassName = driver
                .findElement(By
                        .xpath("//div[@class='title' and contains(text(),'" + appRegistryOption1 + "')]/../.."))
                .getAttribute("class");
        executeJavascript("document.getElementsByClassName('" + bookClassName
                + "')[0].getElementsByTagName('a')[0].style.display = 'block';");
        isElementDisplayed(element("addProvision_btn", appRegistryOption1));
        element("addProvision_btn", appRegistryOption1).click();
        System.out.println("App provisioned");

    } catch (ElementNotFoundException | TimeoutException e) {
        System.out.println("Already provisioned");

    }
}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

private void closeRefresh() {

    driver.findElement(By.xpath("//a[@title='Close']")).click();

}

From source file:com.cengage.mindtap.keywords.MasterPageActions.java

private void closeEdit() {

    driver.findElement(By.xpath("//a[@class='nb_closeIcon nb_closeRight']")).click();

}