Monday, July 18, 2016

Project Aardvark: Script 1, Basic page checks

// This is the code for the basic PageCheck for
// "Project Aardvark"
// Mike Talks 18/05/2016

// This code is customised from
// http://www.seleniumhq.org/docs/03_webdriver.jsp#setting-up-a-selenium-webdriver-project


// The following declarations import required packages from the
// Selenium .jar libraries we included in our project
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class PageChecker {

    public static void main(String[] args) {

        // Create a new instance of the Firefox driver
        // This copies all the information about the page we've loaded into
        // the page_item object
        WebDriver page_item = new FirefoxDriver();
       
        // Open our target page ... a previous blog article
        page_item.get("http://testsheepnz.blogspot.co.nz/2016/07/im-hoping-that-this-blog-will-have-most.html");
       
        // Print out the page title
        System.out.println("Page title is: " + page_item.getTitle());
       
        // Confirm if there is a blue aardvark in the page
        if ( page_item.getPageSource().contains("blue aardvark"))
        {
            System.out.println("Whole page contains blue aardvark");
        }

        // Confirm if there is a redaardvark in the page
        if ( page_item.getPageSource().contains("red aardvark"))
        {
            System.out.println("Whole page contains red aardvark");
        }       
       
        // We are now going to capture an element of the current page
        // I've used developer tools to find the ID for it
        // This is the main body of the piece (and excludes comments & title)
        WebElement element = page_item.findElement(By.id("post-body-8711143007795160191"));
       
        // Confirm if there is a blue aardvark in the element
        if ( element.getText().contains("blue aardvark"))
        {
            System.out.println("Original post element contains blue aardvark");
        }

        // Confirm if there is a red aardvark in the element
        if ( element.getText().contains("red aardvark") )
        {
            System.out.println("Original post element contains red aardvark");
        }               
    }

}

1 comment:

  1. จีคลับ Channels for online games and interesting bets.

    จีคลับ Online casinos are the starting point for millions of people who are credited as the starting point for making good money for playing games. Online gambling with websites is considered to be very popular in Thailand because of who? It is well known that this online casino site offers online gambling services that can earn the player the easiest and quickest.

    Just by overcoming the online bets you play, you can earn money for yourself, so if you are thinking of playing online gambling games, then you want to opt for this site. You can only make money online with just a few minutes and you can make millions of dollars for you.

    And when you know this, do not forget to join the fun. And to play online games, all you want to play is because the team of the site. Our online casino is welcome and ready to serve you 24 hours, sure enough. If you are going to make millions to play with our online casino. บาคาร่า

    ReplyDelete