com.inc108.webdriver2.MyFirstTest.java Source code

Java tutorial

Introduction

Here is the source code for com.inc108.webdriver2.MyFirstTest.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.inc108.webdriver2;

//import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

/**
 *
 * @author lenovo
 */

public class MyFirstTest {

    @Test
    public void startWebDriver() {
        WebDriver driver = new FirefoxDriver();
        driver.navigate().to("http://ww16.sec.cl/ciige3/");

        if (driver instanceof JavascriptExecutor) {
            ((JavascriptExecutor) driver).executeScript("console.log('im js from webdriver selenium!!!');");
        }
        String[] units = { "12", "13", "15", "22", "24", "25", "26", "31", "32", "33", "35", "37", "41", "44", "46",
                "51", "52", "53", "54", "56", "57", "61", "62", "63", "64", "66", "71", "72", "73", "74", "77",
                "81", "82", "83", "84", "85", "86", "87", "91", "92", "93", "94", "95", "96", "97", "101", "102",
                "103", "104", "105", "106", "107", "111", "112", "113", "114", "115", "116", "121", "122", "124",
                "125", "126", "127", "131", "134", "141", "142", "143", "145", "151", "152", "155", "157", "161",
                "162", "164", "165", "166", "167", "171", "173", "175", "181", "182", "183", "185", "186", "191",
                "192", "193", "195", "197" };
        String cigeNumber = "835805";

        driver.findElement(By.xpath(
                ".//*[@id='cuerpo']/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[1]/td[2]/input"))
                .sendKeys("13.432.595-k");

        driver.findElement(By.xpath(
                ".//*[@id='cuerpo']/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/input"))
                .sendKeys("76.001.876-7");

        driver.findElement(By.xpath(
                ".//*[@id='cuerpo']/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[3]/td[2]/input"))
                .sendKeys("vre8401");
        //click aceptar
        driver.findElement(By.xpath(
                ".//*[@id='cuerpo']/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[1]/td/table[2]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[5]/td[2]/a[1]"))
                .click();
        //click procesos en construccion
        driver.findElement(By.xpath(
                ".//*[@id='menu']/tbody/tr[2]/td/table/tbody/tr[2]/td/table/tbody/tr[1]/td[2]/table/tbody/tr[7]/td/div/a"))
                .click();
        //enter proceso id
        driver.findElement(By.xpath(
                ".//*[@id='cuerpo']/table/tbody/tr/td/table[2]/tbody/tr[1]/td[2]/form/table/tbody/tr[2]/td[2]/input"))
                //        .sendKeys("840480");
                .sendKeys(cigeNumber);
        //click buscar
        driver.findElement(By.xpath(".//*[@id='cuerpo']/table/tbody/tr/td/table[2]/tbody/tr[1]/td[2]/form/a"))
                .click();
        //click on cige number link
        driver.findElement(By.xpath(".//*[@id='tabla']/tbody/tr/td[1]/a")).click();
        //paso uno - click siguiente
        driver.findElement(By.xpath(".//*[@id='Tabla_01']/tbody/tr/td/a")).click();
        //paso 2 - click siguiente
        driver.findElement(By.xpath(".//*[@id='Tabla_01']/tbody/tr/td[3]/a")).click();
        //        Assert.assertTrue("title should start with selenium simplified", driver.getTitle().startsWith("Selenium Simplified"));

        //        driver.close();
        //        driver.quit();
    }
}