Example usage for org.openqa.selenium WebDriver manage

List of usage examples for org.openqa.selenium WebDriver manage

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver manage.

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:WaitTool.java

License:Open Source License

/** Waits for the completion of Ajax jQuery processing by checking "return jQuery.active == 0" condition.
 *
 * @param WebDriver - The driver object to be used to wait and find the element
 * @param int - The time in seconds to wait until returning a failure
 *
 * @return boolean true or false(condition fail, or if the timeout is reached)
 * *//*  w ww  . jav a2  s.c om*/
public static boolean waitForJQueryProcessing(WebDriver driver, int timeOutInSeconds) {
    boolean jQcondition = false;
    try {
        driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
        new WebDriverWait(driver, timeOutInSeconds) {
        }.until(new ExpectedCondition<Boolean>() {

            @Override
            public Boolean apply(WebDriver driverObject) {
                return (Boolean) ((JavascriptExecutor) driverObject).executeScript("return jQuery.active == 0");
            }
        });
        jQcondition = (Boolean) ((JavascriptExecutor) driver).executeScript("return jQuery.active == 0");
        driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
        return jQcondition;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return jQcondition;
}

From source file:WaitTool.java

License:Open Source License

/**
 * Coming to implicit wait, If you have set it once then you would have to explicitly set it to zero to nullify it -
 *//*from   w  w  w  . j  a v a2 s  .  c  o m*/
public static void nullifyImplicitWait(WebDriver driver) {
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
}

From source file:WaitTool.java

License:Open Source License

/**
 * Set driver implicitlyWait() time./* ww w.java2 s  .c o  m*/
 */
public static void setImplicitWait(WebDriver driver, int waitTime_InSeconds) {
    driver.manage().timeouts().implicitlyWait(waitTime_InSeconds, TimeUnit.SECONDS);
}

From source file:WaitTool.java

License:Open Source License

/**
 * Reset ImplicitWait.//from  w ww. j a  v  a2  s.  co  m
 * To reset ImplicitWait time you would have to explicitly
 * set it to zero to nullify it before setting it with a new time value.
 */
public static void resetImplicitWait(WebDriver driver) {
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
    driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait
}

From source file:WaitTool.java

License:Open Source License

/**
 * Reset ImplicitWait.// www .  j  a va 2 s . c  o m
 * @param int - a new wait time in seconds
 */
public static void resetImplicitWait(WebDriver driver, int newWaittime_InSeconds) {
    driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
    driver.manage().timeouts().implicitlyWait(newWaittime_InSeconds, TimeUnit.SECONDS); //reset implicitlyWait
}

From source file:Practice01.java

public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    // Open Website
    driver.get("https://enterprise-demo.orangehrmlive.com/auth/login");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    // Type Username
    driver.findElement(By.xpath("//input[@id='txtUsername']")).sendKeys("Admin");
    // Type Password
    driver.findElement(By.cssSelector("#txtPassword")).sendKeys("admin");
    // Click on Login
    driver.findElement(By.id("btnLogin")).click();
    // Click on PIM
    driver.findElement(By.id("menu_pim_viewPimModule")).click();
    // Click Add Employee
    driver.findElement(By.xpath("//a[@id='menu_pim_addEmployee']")).click();
    //        DateFormat dateFormat = new SimpleDateFormat("ddhhss");
    //        Date date = new Date();
    //        String date1 = dateFormat.format(date);
    //        String userName = "John"+date1;
    //        String username1= "Smith"+date1;
    // Type First name
    driver.findElement(By.id("firstName")).sendKeys("John");
    // Type Last name
    driver.findElement(By.id("lastName")).sendKeys("Smith");
    Random random = new Random();
    int eID = random.nextInt(1000);
    // Click on Location
    driver.findElement(By.id("employeeId")).clear();
    driver.findElement(By.id("employeeId")).sendKeys("" + eID);
    // Click on//from   w ww . j a va2  s.c o  m
    WebElement location_dd = driver.findElement(By.xpath("//select[@id='location']"));
    Select location = new Select(location_dd);
    location.selectByIndex(9);
    // Click Save
    driver.findElement(By.id("btnSave")).click();
    // Click on edit
    driver.findElement(By.xpath("//input[@value='Edit']")).click();
    // Click on licences expiry
    driver.findElement(By.id("personal_txtLicExpDate")).click();
    // Select date
    driver.findElement(By.xpath("html/body/div[4]/table/tbody/tr[5]/td[2]/a")).click();
    // Click on marital box
    driver.findElement(By.id("personal_cmbMarital")).click();
    // Click on married
    driver.findElement(By.xpath("//select[@name='personal[cmbMarital]']/option[3]")).click();
    // Click on Dob box
    driver.findElement(By.id("personal_DOB")).click();
    //click month box
    Select month_dd = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicker-title']/select[1]")));
    month_dd.selectByVisibleText("Jul");
    // Select Year
    Select year_dd = new Select(driver.findElement(By.xpath("//div/select[2]")));
    year_dd.selectByIndex(35);
    // Click on Date
    driver.findElement(By.xpath("//table/tbody/tr[4]/td[4]/a")).click();
    // Click Save
    driver.findElement(By.id("btnSave")).click();
    // Verify Successfully Saved Message
    //Assert
    Assert.assertTrue("Successfully Saved",
            driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).isEnabled());
    System.out.println("Successfully Saved");
    //assert1
    //        String expectedText = "Successfully Saved";
    //        String actualText = driver.findElement(By.xpath("html/body/div[1]/div[3]/div/div[2]/div[2]/div")).getText();
    //        Assert.assertEquals(expectedText,actualText);

    // Click Employee List
    driver.findElement(By.id("menu_pim_viewEmployeeList")).click();
    //        Thread.sleep(3000);
    //        //click on emp name
    //        driver.findElement(By.xpath("//input[@id='empsearch_employee_name_empName']")).sendKeys(userName + username1);

    //        // Type Employee ID
    //        driver.findElement(By.id("empsearch_id")).sendKeys(" "+eID);
    //        // Clear Employee ID
    //        driver.findElement(By.id("empsearch_id")).clear();
    Thread.sleep(2000);
    // Search Emp by ID
    driver.findElement(By.id("empsearch_id")).sendKeys("" + eID);
    // Search Employee By ID
    //        driver.findElement(By.id("searchBtn")).click();
    Thread.sleep(2000);
    driver.findElement(By.id("searchBtn")).click();

    //Assert
    Assert.assertTrue("John", driver.findElement(By.xpath("//tbody/tr/td[3]/a")).isEnabled());
    System.out.println("John");

    //
}

From source file:acceptance.SharedDriver.java

License:Open Source License

private static WebDriver createWebDriver() {
    String driverType = getWebDriverType();
    final WebDriver driver;
    switch (driverType.toLowerCase()) {
    case "htmlunit":
        driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24);
        break;/*from  ww w.j  a  v  a 2s  .c  o  m*/
    case "firefox":
        driver = new FirefoxDriver();
        break;
    case "phantomjs":
        String phantomjsBinaryPath = getPhantomjsBinaryPath();
        if (phantomjsBinaryPath.length() > 0) {
            DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
            desiredCapabilities.setCapability("phantomjs.binary.path", phantomjsBinaryPath);
            driver = new PhantomJSDriver(desiredCapabilities);
        } else {
            driver = new PhantomJSDriver();
        }
        break;
    default:
        throw new RuntimeException(
                "WebDriver type not correctly configured. Unknown driver type: '" + driverType + "'");
    }
    driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    driver.manage().window().setSize(new Dimension(1280, 800));
    return driver;
}

From source file:akori.AKORI.java

public static void main(String[] args) throws IOException, InterruptedException {
    System.out.println("esto es AKORI");

    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\";
    NAME = "mbauchile.png";
    // Extrar DOM tree

    Document doc = Jsoup.connect(URL).timeout(0).get();

    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    int xmax = driver.manage().window().getSize().width;
    int ymax = driver.manage().window().getSize().height;

    // Go to the URL page
    driver.get(URL);//from www.j ava  2  s.  c o m

    File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screen, new File(PATH + NAME));

    BufferedImage img = ImageIO.read(new File(PATH + NAME));
    //Graphics2D graph = img.createGraphics();

    BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB);
    Graphics2D graph1 = img.createGraphics();
    double[][] matrix = new double[ymax][xmax];
    BufferedReader in = new BufferedReader(new FileReader("et.txt"));
    String linea;
    double max = 0;
    graph1.drawImage(img, 0, 0, null);
    HashMap<String, Integer> lista = new HashMap<String, Integer>();
    int count = 0;
    for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) {
        String[] datos = linea.split(",");
        int x = (int) Double.parseDouble(datos[0]);
        int y = (int) Double.parseDouble(datos[2]);
        long time = Double.valueOf(datos[4]).longValue();
        if (x >= xmax || y >= ymax)
            continue;
        if (time < 691215)
            continue;
        if (time > 705648)
            break;
        if (lista.containsKey(x + "," + y))
            lista.put(x + "," + y, lista.get(x + "," + y) + 1);
        else
            lista.put(x + "," + y, 1);
        ++count;
    }
    System.out.println(count);
    in.close();
    Iterator iter = lista.entrySet().iterator();
    Map.Entry e;
    for (String key : lista.keySet()) {
        Integer i = lista.get(key);
        if (max < i)
            max = i;
    }
    System.out.println(max);
    max = 0;
    while (iter.hasNext()) {
        e = (Map.Entry) iter.next();
        String xy = (String) e.getKey();
        String[] datos = xy.split(",");
        int x = Integer.parseInt(datos[0]);
        int y = Integer.parseInt(datos[1]);
        matrix[y][x] += (int) e.getValue();
        double aux;
        if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) {
            max = aux;
        }
        //normalMatrix(matrix,x,y,20);
        if (matrix[y][x] > max)
            max = matrix[y][x];
    }
    int A, R, G, B, n;
    for (int i = 0; i < xmax; ++i) {
        for (int j = 0; j < ymax; ++j) {
            if (matrix[j][i] != 0) {
                n = (int) Math.round(matrix[j][i] * 100 / max);
                R = Math.round((255 * n) / 100);
                G = Math.round((255 * (100 - n)) / 100);
                B = 0;
                A = Math.round((255 * n) / 100);
                ;
                if (R > 255)
                    R = 255;
                if (R < 0)
                    R = 0;
                if (G > 255)
                    G = 255;
                if (G < 0)
                    G = 0;
                if (R < 50)
                    A = 0;
                graph1.setColor(new Color(R, G, B, A));
                graph1.fillOval(i, j, 1, 1);
            }
        }
    }
    //graph1.dispose();

    ImageIO.write(img, "png", new File("example.png"));
    System.out.println(max);

    graph1.setColor(Color.RED);
    // Extraer elementos
    Elements e1 = doc.body().getAllElements();
    int i = 1;
    ArrayList<String> tags = new ArrayList<String>();
    for (Element temp : e1) {

        if (tags.indexOf(temp.tagName()) == -1) {
            tags.add(temp.tagName());

            List<WebElement> query = driver.findElements(By.tagName(temp.tagName()));
            for (WebElement temp1 : query) {
                Point po = temp1.getLocation();
                Dimension d = temp1.getSize();
                if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0)
                    continue;
                System.out.println(i + " " + temp.nodeName());
                System.out.println("  x: " + po.x + " y: " + po.y);
                System.out.println("  width: " + d.width + " height: " + d.height);
                graph1.draw(new Rectangle(po.x, po.y, d.width, d.height));
                ++i;
            }
        }
    }

    graph1.dispose();
    ImageIO.write(img, "png", new File(PATH + NAME));

    driver.quit();

}

From source file:akori.Features.java

public static void main(String[] args) throws IOException, InterruptedException {

    URL = "http://www.mbauchile.cl";

    Document doc = Jsoup.connect(URL).timeout(0).get();

    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();

    driver.get(URL);/*w  w  w.j  a v  a  2  s. c o  m*/

    Elements e1 = doc.body().getAllElements();
    Element e = doc.body();
    PrintWriter writer = new PrintWriter("features.txt", "UTF-8");
    int i = 1;
    //        String[][] matrix = new String[e1.size()][10];

    //        traverse(e, 1, 1, "", 1, writer, driver);

    ArrayList<String> tags = new ArrayList<String>();
    System.out.println("");
    //        for (Element temp : e1) {
    //            if (!temp.nodeName().equals("br")) {
    //                writer.println(i + "," + temp.hashCode() + "," + temp.nodeName() + "," + temp.id());
    //                //System.out.println(i+","+temp.hashCode()+","+temp.nodeName());
    //                ++i;
    //            }
    //        }
    i = 1;
    for (Element temp : e1) {
        if (tags.indexOf(temp.tagName()) == -1) {
            tags.add(temp.tagName());
            List<WebElement> query = driver.findElements(By.tagName(temp.tagName()));
            for (WebElement temp1 : query) {
                Point po = temp1.getLocation();
                Dimension d = temp1.getSize();
                if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) {
                    continue;
                }
                if (temp1.getTagName().equals("img"))
                    writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + ","
                            + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("src"));
                else if (temp1.getTagName().equals("a"))
                    writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + ","
                            + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("href"));
                else
                    writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + ","
                            + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText());
                ++i;
            }
        }
    }
    driver.quit();
    writer.close();
}

From source file:akori.SELENIUM.java

public static void main(String[] args) throws Exception {
    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    System.out.println(driver.manage().window().getSize().toString());
    System.out.println(driver.manage().window().getPosition().toString());
    URL = "http://www.mbauchile.cl";
    PATH = "E:\\NetBeansProjects\\AKORI\\1.png";

    // Go to the Google Suggest home page
    driver.get(URL);//from   w  ww .  j  a v  a  2 s. c om

    // Enter the query string "Cheese"
    WebElement query = driver.findElement(By.id("container"));
    Point p = query.getLocation();
    Dimension d = query.getSize();

    System.out.println("x: " + p.x + " y: " + p.y);
    System.out.println("width: " + d.width + " height: " + d.height);

    driver.quit();
}