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:StoryKeyboardShortcutTests.java

@Test
public void storyFirstTest() throws InterruptedException {

    //1. Go to story site
    driver.get(/*from   w  ww  . ja va  2s . c om*/
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //2. Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //Click on video tab
    WebElement videoTab = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[1]/div/div/div/table[1]/tbody[2]/tr[1]/td[1]/div/div/div[2]"));
    videoTab.click();
    WebElement searchText = driver.findElement(By.id("isc_30"));
    searchText.sendKeys("SSS_2477_01.mov");

    Thread.sleep(5000);
    WebElement selectVideo = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));

    selectVideo.click();

    WebElement selectVideo1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));
    selectVideo1.click();

    Thread.sleep(2000);
    WebElement timeLine = driver.findElement(By.cssSelector("svg[id=multimedia_ClearInOut]"));
    timeLine.click();

    Thread.sleep(2000);
    int xp1 = 0;
    WebElement testtimecode1 = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp1 + ":')]"));
    final String starttime = testtimecode1.getText();

    Actions action = new Actions(driver);
    action.sendKeys(Keys.SPACE).build().perform();
    System.out.println(testtimecode1.getText());

    int ourtime = 9000;
    Thread.sleep(ourtime);
    int xp = (ourtime - 1000) / 1000;
    action.sendKeys(Keys.SPACE).build().perform();
    Thread.sleep(2000);

    timeLine.click();
    Thread.sleep(2000);
    WebElement testtimecode = driver.findElement(By.xpath("//*[contains(text(),'00:0" + xp + ":')]"));

    System.out.println(testtimecode.getText());
    System.out.println(testtimecode1.getText());

    Assert.assertNotEquals(testtimecode.getText(), starttime);
    //Assert.assertNotEquals("111", "1");

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyboardFrameForward() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(//from  w ww.j av a  2 s  . c om
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    System.out.println(timevalue);
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    action.sendKeys(Keys.DECIMAL).build().perform();

    WebElement timebarnumber2 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']//small"));
    final String timevalue2 = timebarnumber.getText();

    final String firsttime = (timevalue1.substring(timevalue2.lastIndexOf(":") + 1));
    int timer1 = Integer.parseInt(firsttime);

    final String secondtime = (timevalue2.substring(timevalue2.lastIndexOf(":") + 1));
    int timer2 = Integer.parseInt(secondtime);

    System.out.println(timer1);
    System.out.println(timer2);
    Assert.assertEquals(timer1 + 1, timer2);

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyboardFrameBackward() throws InterruptedException {
    //a. Launch story in firefox
    driver.get(/*from  w ww.j av  a 2  s  .com*/
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    System.out.println(timevalue);
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    action.sendKeys(Keys.SEPARATOR).build().perform();

    WebElement timebarnumber2 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']//small"));
    final String timevalue2 = timebarnumber.getText();

    final String firsttime = (timevalue1.substring(timevalue2.lastIndexOf(":") + 1));
    int timer1 = Integer.parseInt(firsttime);

    final String secondtime = (timevalue2.substring(timevalue2.lastIndexOf(":") + 1));
    int timer2 = Integer.parseInt(secondtime);

    System.out.println(timer1);
    System.out.println(timer2);
    Assert.assertEquals(timer1 - 1, timer2);

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyDelete() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(// ww w.  j av a2 s. c o m
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();

    Thread.sleep(2000);

    WebElement timebarnumber = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue = timebarnumber.getText();

    WebElement timebarnumber1 = driver.findElement(
            By.xpath("//div[contains(@style,'POSITION') and @eventproxy='sta_timeline_cursorlabel_1']"));
    final String timevalue1 = timebarnumber.getText();

    Actions action = new Actions(driver);

    //Asserting if presence of element shows false after deletion button is pressed
    action.sendKeys(Keys.DELETE).build().perform();
    Boolean isPresent2 = driver.findElements(By.cssSelector("div[class='thumbnailStrip']")).size() > 0;
    Assert.assertEquals(false, isPresent2);

    // Undoing the change to timeline by pressing 'CTRL + Z'
    Thread.sleep(2000);
    Actions action2 = new Actions(driver);
    action2.keyDown(Keys.CONTROL).sendKeys(String.valueOf('\u007A')).perform();

    /*
    Thread.sleep(2000);
    Actions action = new Actions(driver);
    //String selectAll = Keys.chord(Keys.CONTROL, "a");
            
    action.sendKeys(".").perform();
    // action.sendKeys(selectAll).build().perform();
    //action.sendKeys(Keys.getKeyFromUnicode('selectAll')).build().perform();
    */

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyVolumeBar() throws InterruptedException {

    //a. Launch story in firefox
    driver.get(/*from ww w  . jav  a  2 s  .  c om*/
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //From storytab double click on story named 'storytest'
    Thread.sleep(2000);
    WebElement storytest = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));
    storytest.click();
    WebElement storytest1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div/div[3]"));

    storytest1.click();
    storytest1.click();

    Thread.sleep(3000);
    //Select the video element in timeline div[class="thumbnailStrip"]
    WebElement timelinebar = driver.findElement(By.cssSelector("div[class='thumbnailStrip']"));
    timelinebar.click();
    Thread.sleep(3000);
    Actions action = new Actions(driver);
    action.sendKeys("a").perform();
    //html/body/div[7]/div/div
    Boolean isPresent2 = driver.findElements(By.xpath("html/body/div[7]/div/div")).size() > 0;

    System.out.println(isPresent2);
    Assert.assertEquals(false, isPresent2);

}

From source file:StoryKeyboardShortcutTests.java

@Test
public void storyKeyboardMute() throws InterruptedException {

    //1. Go to story site
    driver.get(//  w w w. java 2  s  .  c o m
            "http://tanveer-pc:9724/web/story/story.html?debug&storyhub=tanveer-pc&gh=Guest/@tanveer-pc&pilot=tanveer-pc&preview=tanveer-pc&mediaservice=tanveer-pc");
    //driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

    WebDriverWait wait = new WebDriverWait(driver, 15);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']")));

    //2. Close the license popup
    WebElement okButton = driver.findElement(By.cssSelector(
            "img[src='http://tanveer-pc:9724/web/story/story/sc/skins/vizrt/images/Editor/Close.png']"));
    okButton.click();

    //Click on Media tab
    WebElement uploadButton = driver.findElement(
            By.xpath("html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[1]/div[1]/div/table/tbody/tr/td"));
    uploadButton.click();

    //Click on video tab
    WebElement videoTab = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[1]/div/div/div/table[1]/tbody[2]/tr[1]/td[1]/div/div/div[2]"));
    videoTab.click();
    WebElement searchText = driver.findElement(By.id("isc_30"));
    searchText.sendKeys("SSS_2477_01.mov");

    Thread.sleep(5000);
    WebElement selectVideo = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));

    selectVideo.click();

    WebElement selectVideo1 = driver.findElement(By.xpath(
            "html/body/div[4]/div/div[1]/div/div[1]/div/div[2]/div[3]/div/div/div/div/div[2]/div[2]/div[3]/div[1]/div[3]"));
    selectVideo1.click();

    /*
            Thread.sleep(2000) ;
            WebElement timeLine = driver.findElement(By.cssSelector("svg[id=multimedia_ClearInOut]"));
            timeLine.click();
            
            Thread.sleep(2000);
            int xp1=0;
            WebElement testtimecode1 = driver.findElement(By.xpath("//*[contains(text(),'00:0"+xp1+":')]"));
            final String starttime = testtimecode1.getText();
            
            Actions action = new Actions(driver);
            action.sendKeys(Keys.SPACE).build().perform();
            System.out.println(testtimecode1.getText());
            
            int ourtime = 9000;
            Thread.sleep(ourtime);
            int xp = (ourtime-1000)/1000;
            action.sendKeys(Keys.SPACE).build().perform();
            Thread.sleep(2000);
            
            timeLine.click();
            Thread.sleep(2000);
            WebElement testtimecode = driver.findElement(By.xpath("//*[contains(text(),'00:0"+xp+":')]"));
            
            System.out.println(testtimecode.getText());
            System.out.println(testtimecode1.getText());
            
            Assert.assertNotEquals(testtimecode.getText(), starttime);
            //Assert.assertNotEquals("111", "1");
    */
}

From source file:LoginAcceptanceTests.java

License:Open Source License

@Test
public void testLogin() throws Exception {

    // Test failed login
    webDriver.get(baseUrl + "/login");

    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys("invalidpassword");
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Welcome!"));

    // Test successful login
    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys("password");
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));

    // Test logout
    webDriver.get(baseUrl + "/logout.do");

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Welcome!"));
}

From source file:facets_testing.java

@Test
public void testCreatorFacet() {
    driver.setJavascriptEnabled(true);//  w  w  w.  j  a  va 2  s. c o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        String element_text = driver.findElement(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[1]/b"))
                .getText();
        System.out
                .println(driver.findElement(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[1]/b")).getText());
        assertEquals(element_text, "Creator");
    } catch (Exception e) {
        System.out.println("Creator facet is not present.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testCreatorLinkPresent() {
    List<String> creator_name = new ArrayList<>();
    driver.setJavascriptEnabled(true);// w  ww . ja  v a 2s. c  o m
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creator_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement creator : creator_list) {
            creator_name.add(creator.getText());
        }
        assertThat(creator_name, JUnitMatchers.hasItem("Shwachman, Irene"));
    } catch (Exception e) {
        System.out.println("Creator name is not present.Error : " + e);
    }
}

From source file:facets_testing.java

@Test
public void testCreatorLinkNotPresent() {
    List<String> creator_name = new ArrayList<>();
    driver.setJavascriptEnabled(true);//from   w  w w.j a va2  s.  c om
    try {
        driver.get(page_url);
        Thread.sleep(14);
        List<WebElement> creator_list = driver
                .findElements(By.xpath("//div[@id=\"drs_creator_sim\"]/div/div[2]/a/div[1]"));
        for (WebElement creator : creator_list) {
            creator_name.add(creator.getText());
        }
        assertThat(creator_name, not(JUnitMatchers.hasItem("abcdef")));
    } catch (Exception e) {
        System.out.println("Creator name is falsely present.Error : " + e);
    }
}