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:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void clickConfirmYesButton() throws Throwable {
    WebElement confirmBtn = driver//from www .j a v  a2s  .c o m
            .findElement(By.xpath("/html/body/div[1]/div[1]/div[5]/div/div/div[3]/button[1]"));
    confirmBtn.click();
}

From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java

public void clickConfirmNoButton() throws Throwable {
    WebElement cancelBtn = driver/*from   w w  w  . j a  v  a2s .  c  o  m*/
            .findElement(By.xpath("/html/body/div[1]/div[1]/div[5]/div/div/div[3]/button[2]"));
    cancelBtn.click();
}

From source file:cls.ui.model.selenium.secondhandcarmanagement.StartAssessmentPage.java

public void selectBrand(String letter, String brand) throws Throwable {
    WebElement brandInput = driver.findElement(By.id("getBrand"));
    brandInput.click();/* w w  w  .j  a  v  a 2s  . c  o  m*/

    List<WebElement> letterLst = driver.findElements(By.xpath(
            "/html/body/div/div/div/div/div/div[2]/div[1]/div/div[1]/div/div/form/div[2]/div[2]/div[2]/div[1]/div/ul/div[2]/a"));
    for (int i = 0; i < letterLst.size(); i++) {
        WebElement letterBtn = letterLst.get(i);
        if (letterBtn.getText().equals(letter)) {
            letterBtn.click();
            break;
        }
    }

    List<WebElement> brandLst = driver.findElements(By.xpath(
            "/html/body/div[1]/div/div/div/div/div[2]/div[1]/div/div[1]/div/div/form/div[2]/div[2]/div[2]/div[1]/div/ul/div[1]/li"));
    for (int i = 0; i < brandLst.size(); i++) {
        WebElement brandBtn = brandLst.get(i);
        if (brandBtn.getText().equals(brand)) {
            brandBtn.click();
            break;
        }
    }

    Thread.sleep(1000);
}

From source file:cls.ui.model.selenium.secondhandcarmanagement.StartAssessmentPage.java

public void clickSubmitButton() throws Throwable {
    WebElement submitBtn = driver.findElement(By
            .xpath("/html/body/div[1]/div/div/div/div/div[2]/div[1]/div/div[1]/div/div/div[2]/div/button[1]"));
    submitBtn.click();/*from www  .  j  a  va 2 s. c  om*/
    Thread.sleep(1000);
}

From source file:cn.aozhi.songify.functional.gui.RegisterFT.java

License:Apache License

@Test
public void inputInValidateValue() {
    s.open("/register");
    s.click(By.id("submit_btn"));

    assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo("");
}

From source file:cn.aozhi.songify.functional.gui.TaskGuiFT.java

License:Apache License

@Test
public void inputInValidateValue() {
    s.open("/task/");
    s.click(By.linkText(""));
    s.click(By.id("submit_btn"));

    assertThat(s.getText(By.xpath("//fieldset/div/div/span"))).isEqualTo("");
}

From source file:cn.edu.hfut.dmic.webcollector.example.FirefoxSelenium3.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Executor executor = new Executor() {
        @Override/*from www . j a v a2s  .co  m*/
        public void execute(CrawlDatum datum, CrawlDatums next) throws Exception {
            MongoClient mongoClient = new MongoClient("localhost", 27017);
            // ?
            // DBCollection dbCollection = mongoClient.getDB("maoyan_crawler").getCollection("rankings_am"); 
            DB db = mongoClient.getDB("maoyan_crawler");
            // ?????
            Set<String> colls = db.getCollectionNames();
            for (String s : colls) {
                // Collection(?"")
                if (s.equals("attend_rate")) {
                    db.getCollection(s).drop();
                }
            }
            DBCollection dbCollection = db.getCollection("attend_rate");
            ProfilesIni pi = new ProfilesIni();
            FirefoxProfile profile = pi.getProfile("default");
            WebDriver driver = new FirefoxDriver(profile);
            driver.manage().window().maximize();
            driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
            //                driver.setJavascriptEnabled(false);
            driver.get(datum.getUrl());
            //                System.out.println(driver.getPageSource());
            driver.findElement(By.xpath("//*[@id='seat_city']")).click();
            driver.switchTo().window(driver.getWindowHandle());

            int city_num = driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).size();
            for (int i = 0; i < city_num; i++) {
                System.out.println("A city chosen" + i);
                System.out.println(
                        driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i).getText());
                String city = driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i)
                        .getText();
                ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);",
                        driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i));
                ((JavascriptExecutor) driver).executeScript("window.scrollBy(0, -250)", "");
                Thread.sleep(1000);
                new Actions(driver)
                        .moveToElement(
                                driver.findElements(By.xpath("//div[@id='all-citys']/div/ul/li/a")).get(i))
                        .click().perform();
                driver.switchTo().window(driver.getWindowHandle());
                //                System.out.println(driver.findElement(By.xpath("//span[@class='today']/em")).getText());
                System.out.println(driver.findElement(By.xpath("//span[@class='today']")).getText());
                for (int j = 0; j < driver
                        .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']"))
                        .size(); j++) {
                    System.out.println(driver
                            .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']"))
                            .get(j).getText());
                    System.out.println(
                            driver.findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c2 red']"))
                                    .get(j).getText());
                    System.out.println(
                            driver.findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c3 gray']"))
                                    .get(j).getText());
                    BasicDBObject dbObject = new BasicDBObject();
                    dbObject.append("title", driver.findElement(By.xpath("//span[@class='today']")).getText())
                            .append("city", city)
                            .append("mov_cnname",
                                    driver.findElements(
                                            By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']"))
                                            .get(j).getText())
                            .append("boxoffice_rate", driver
                                    .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c2 red']"))
                                    .get(j).getText())
                            .append("visit_pershow", driver
                                    .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c3 gray']"))
                                    .get(j).getText());
                    dbCollection.insert(dbObject);
                }
                System.out.println("new city list to choose");
                new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[@id='seat_city']"))).click()
                        .perform();
                driver.switchTo().window(driver.getWindowHandle());
                Thread.sleep(500);
            }
            driver.close();
            driver.quit();
            mongoClient.close();
        }
    };

    //DBDBManager
    DBManager manager = new BerkeleyDBManager("crawl");
    //Crawler?DBManagerExecutor
    Crawler crawler = new Crawler(manager, executor);
    crawler.addSeed("http://pf.maoyan.com/attend/rate");
    crawler.start(1);
}

From source file:cn.edu.hfut.dmic.webcollector.example.FirefoxSelenium4.java

License:Open Source License

public static void main(String[] args) throws Exception {
    Executor executor = new Executor() {
        @Override//w  w  w  .  j a  v a  2  s.c  o  m
        public void execute(CrawlDatum datum, CrawlDatums next) throws Exception {
            MongoClient mongoClient = new MongoClient("localhost", 27017);
            // ?
            // DBCollection dbCollection = mongoClient.getDB("maoyan_crawler").getCollection("rankings_am"); 
            DB db = mongoClient.getDB("maoyan_crawler");
            // ?????
            Set<String> colls = db.getCollectionNames();
            for (String s : colls) {
                // Collection(?"")
                if (s.equals("rankings_am")) {
                    db.getCollection(s).drop();
                }
            }
            DBCollection dbCollection = db.getCollection("attend_rate");
            ProfilesIni pi = new ProfilesIni();
            FirefoxProfile profile = pi.getProfile("default");
            WebDriver driver = new FirefoxDriver(profile);
            driver.manage().timeouts().pageLoadTimeout(3, TimeUnit.SECONDS);
            //                driver.setJavascriptEnabled(false);
            driver.get(datum.getUrl());
            //                System.out.println(driver.getPageSource());
            List<WebElement> movie_name = driver
                    .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c1 lineDot']"));
            List<WebElement> boxoffice_rate = driver
                    .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c2 red']"));
            List<WebElement> visit_pershow = driver
                    .findElements(By.xpath("//div[@id='seat_table']//ul//li[@class='c3 gray']"));
            WebElement title = driver.findElement(By.xpath("//span[@class='today']/em"));
            WebElement title2 = driver.findElement(By.xpath("//span[@class='today']"));
            System.out.println(title.getText());
            System.out.println(title.getText());
            for (int i = 0; i < movie_name.size(); i++) {
                System.out.println(movie_name.get(i).getText());
                System.out.println(boxoffice_rate.get(i).getText());
                System.out.println(visit_pershow.get(i).getText());
                //                   BasicDBObject dbObject = new BasicDBObject();
                //                  dbObject.append("title", title).append("rank", amList.get(0)).append("mov_cnname", cn_name).append("mov_enname", en_name).append("toweek_rev", amList.get(2)).append("total_rev", amList.get(3)).append("val_week", amList.get(4));
                //                   dbCollection.insert(dbObject);
            }
            driver.quit();

        }
    };

    //DBDBManager
    DBManager manager = new BerkeleyDBManager("crawl");
    //Crawler?DBManagerExecutor
    Crawler crawler = new Crawler(manager, executor);
    crawler.addSeed("http://pf.maoyan.com/attend/rate");
    crawler.start(1);
}

From source file:cn.hxh.springside.test.functional.Selenium2.java

License:Apache License

/**
 * ??, ?0, Selnium1.0.//w ww. j ava 2 s  . co  m
 */
public String getTable(WebElement table, int rowIndex, int columnIndex) {
    return table.findElement(By.xpath("//tr[" + (rowIndex + 1) + "]//td[" + (columnIndex + 1) + "]")).getText();
}

From source file:cn.newtouch.util.test.utils.SeleniumUtils.java

License:Apache License

/**
 * Selnium1.0, ?0.//  w ww. j  a  va 2 s .  com
 */
public static String getTable(WebElement table, int rowIndex, int columnIndex) {
    return table.findElement(By.xpath("//tr[" + (rowIndex + 1) + "]//td[" + (columnIndex + 1) + "]")).getText();
}