Example usage for org.openqa.selenium By name

List of usage examples for org.openqa.selenium By name

Introduction

In this page you can find the example usage for org.openqa.selenium By name.

Prototype

public static By name(String name) 

Source Link

Usage

From source file:calc.CalculatorUIT.java

public void testCodesCrud(DesiredCapabilities browser) throws Exception {

    ExtentReports logger = new ExtentReports("target//advancedReport.html", false);
    ExtentTest test1 = logger.startTest("Verify Target String");
    ExtentTest test2 = logger.startTest("Verify Calculation Result");

    WebDriver driver = null;/*ww  w.  jav  a  2  s  . c  om*/
    System.out.println("Attempt connect to Selenium Node @ " + NodeURL);
    File pathToBinary = new File("/opt/firefox46/firefox/firefox-bin");
    FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
    FirefoxProfile firefoxProfile = new FirefoxProfile();
    driver = new FirefoxDriver(ffBinary, firefoxProfile);
    try {
        System.out.println("attempt connect to target: " + TargetURL);
        driver.get(TargetURL);
        //input a addition 12+8 example in the calculator web-application;
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[2]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[3]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[12]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[10]")).click();
        driver.findElement(By.xpath("(//input[@id='buttonRow'])[15]")).click();

        //search target string value
        String targetStr = "Welcome to the Demo";

        //verify result
        boolean isFound = (driver.findElement(By.tagName("body")).getText()).contains(targetStr);
        boolean result = driver.findElement(By.name("display")).getAttribute("value").contains("84");

        //verify title  
        if (isFound == true) {
            test1.log(LogStatus.PASS, "Title has been verified");
        }
        if (isFound == false) {
            test1.log(LogStatus.FAIL, "Title has NOT been verified");
        }

        //verify result     
        if (result == true) {
            test2.log(LogStatus.PASS,
                    "The Calculation result was correct: [12 multiply by 7 gave output of 84]");
        } else {
            test2.log(LogStatus.FAIL,
                    "The Calculation result was not correct [the title is[Welcome to the Demo!]");

        }
        logger.endTest(test1);
        logger.endTest(test2);
        logger.flush();

        System.out.println("look for= [" + targetStr + "]");
        System.out.println("did we find it? [" + isFound + "]");

        System.out.println("calculate 12 multiply by 7");
        System.out.println("Was the result 84 ? [" + result + "]");

        Assert.assertTrue(isFound);
        Assert.assertTrue(result);
        //  Assert.assertEquals("hell",driver.getTitle());
        //doTest(driver); 
        // rest of test commands come here
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(e.getMessage(), false);
    } finally {
        if (driver != null) {
            driver.quit();
        }
    }
}

From source file:ch.vorburger.mifos.wiki.ZWikiScraper.java

License:Apache License

/**
 * Go to the edit page./*from ww w.ja v a  2 s .  co m*/
 * Does the login, if needed.
 * @param pageID zWiki Page ID
 */
private boolean wdGoToEdit(String pageID) {
    String url = wikiBaseURL + pageID + "/editform";
    wd.get(url);
    System.out.println(wd.getCurrentUrl()); // TODO Remove
    try {
        wd.findElement(By.tagName("textarea"));
        // So we're really on the edit page, so return.  
        return true;
    } catch (NoSuchElementException e1) {
        try {
            // We landed on the Plone login page instead of the Wiki edit, so let's login:
            wd.findElement(By.id("__ac_name")).sendKeys(wikiLoginName);
            wd.findElement(By.id("__ac_password")).sendKeys(wikiPassword);
            wd.findElement(By.name("submit")).click();
            // Now textarea must be found (if the login was valid) ...
            // if we have a NoSuchElementException again here, something is wrong
        } catch (NoSuchElementException e2) {
            // Actually not a login page :( This happens if the TOC has an invalid page ID entry
            return false;
        }
        try {
            wd.findElement(By.tagName("textarea"));
            return true;
        } catch (NoSuchElementException e2) {
            System.out.println(wd.getCurrentUrl());
            System.out.println(wd.getTitle());
            System.out.println(wd.getPageSource());
            throw new IllegalStateException(
                    "I am not on the Wiki Edit page as I should be by now, abandoning...");
        }
    }

}

From source file:ch.vorburger.webdriver.reporting.tests.SampleGoogleSearchReportTest.java

License:Apache License

@Test
public void testGoogleSearch() {
    EventFiringWebDriver driverWithReporting;
    {//ww  w  .j av  a 2s .  c om
        // System.setProperty("webdriver.chrome.driver", "/opt/google/chrome/chrome");
        // WebDriver driver = new ChromeDriver();
        WebDriver driver = new FirefoxDriver();

        WebDriverEventListener loggingListener = new LoggingWebDriverEventListener(LOG_FILE_WRITER);
        ;
        driverWithReporting = new EventFiringWebDriver(driver);
        driverWithReporting.register(loggingListener);
    }

    driverWithReporting.get("http://www.google.com");
    WebElement element = driverWithReporting.findElement(By.name("q"));
    element.sendKeys("Mifos");
    element.submit();

    (new WebDriverWait(driverWithReporting, 10))
            .until(ExpectedConditions.presenceOfElementLocated(By.id("bfoot")));

    driverWithReporting.quit();
}

From source file:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java

public static void main(String[] args) {
    try {//from   w w w  .j  a v a 2s .com

        Integer pozSpam = 0;
        Integer pozTrash = 0;
        Integer pozHelp = 0;
        Integer pozCompose = 0;
        Integer pozNewFolder = 0;

        System.setProperty("webdriver.chrome.driver",
                "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe");
        System.setProperty("webdriver.chrome.logfile",
                "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("test-type");
        options.addArguments("--start-maximized");
        options.addArguments("--disable-web-security");
        options.addArguments("--no-proxy-server");
        options.addArguments("--disable-extensions");
        options.addArguments("--disable-notifications");
        options.addArguments("--disable-popup-blocking");
        options.addArguments("--disable-plug-in");
        Map<String, Object> prefs = new HashMap<String, Object>();
        prefs.put("credentials_enable_service", false);
        prefs.put("profile.password_manager_enabled", false);

        options.setExperimentalOption("prefs", prefs);

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true);
        capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true);
        capabilities.setCapability(CapabilityType.PLATFORM, "WIN10");

        driver = new ChromeDriver(capabilities);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://mail.yahoo.com");
        driver.manage().window().maximize();
        WebElement usernameElem = driver.findElement(By.id("login-username"));
        usernameElem.sendKeys("andadeacu@yahoo.com");

        WebElement Next = driver.findElement(By.name("signin"));
        Next.click();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

        WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']"));
        boolean selected = passwordElem.isSelected();

        CharSequence password = "";
        passwordElem.sendKeys(password);

        WebElement login = driver.findElement(By.id("login-signin"));

        login.click();
        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']"));

        List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li"));

        for (int j = 0; j < childs.size(); j++) {

            WebElement spamElem = childs.get(j);
            /*
            * System.out.println("ancorele " + j + " " + " tag " +
            * childs.get(j).getTagName() + " " + childs.get(j).getText() +
            * " " + childs.get(j).getAttribute("innerHTML"));
             */
            if (spamElem.getText().startsWith(("Spam"))) {

                pozSpam = j;

            }
            if (spamElem.getText().startsWith(("Help"))) {

                pozHelp = j;

            }
            if (spamElem.getText().startsWith(("Compose"))) {

                pozCompose = j;

            }
            if (spamElem.getText().startsWith(("New"))) {

                pozNewFolder = j;

            }

            if (spamElem.getText().startsWith(("Trash"))) {
                System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText());
                pozTrash = j;
                break;
            }

        }
        System.out.println(pozTrash);

        WebElement trashElem = childs.get(pozTrash);

        /*
        * System.out.println("trashElem " + trashElem.getTagName() +
        * " text " + trashElem.getText() + " class_atribute " +
        * trashElem.getAttribute("class") + " data_action " +
        * trashElem.getAttribute("data_action"));
         */
        WebElement trashFolderEmpty = trashElem.findElement(
                By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon  icon-delete']"));

        /*
        * System.out.println("spamEmptyFolder " +
        * spamFolderEmpty.getTagName() + " text " +
        * spamFolderEmpty.getText() + " location " +
        * spamFolderEmpty.isEnabled());
         */
        trashFolderEmpty.click();

        int timeOut = 5;

        WebDriverWait wait = new WebDriverWait(driver, timeOut);

        driver.switchTo().alert();

        /* for Chrome is not working 
        WebElement modalPopUp = driver.findElement(By
            .className("modal-hd yui3-widget-hd"));
                
        */

        WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default"));

        /*
        * <button id="okayModalOverlay" class="btn left right default"
        * title="OK" role="button" data-action="ok">OK</button>
         */
        btnDeleteSpamEmails.click();

        driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

        driver.switchTo().activeElement();

        // verify msg after you delete spam emails
        System.out.println(driver.getCurrentUrl());

        driver.quit();
    } catch (Exception ex) {

        ex.printStackTrace();
        driver.quit();
    }

}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectHousingStatus(String housingStatusString) throws Throwable {
    Thread.sleep(1000);/*from  w ww  .j a v a 2 s . c o  m*/
    WebElement housingStatus = driver.findElement(By.name("housingStatus"));
    Select mySelect = new Select(housingStatus);
    mySelect.selectByVisibleText(housingStatusString);
}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectEducation(String educationString) throws Throwable {
    Thread.sleep(1000);//from w  ww . j av a  2  s .c o  m
    WebElement education = driver.findElement(By.name("education"));
    Select mySelect = new Select(education);
    mySelect.selectByVisibleText(educationString);
}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectProfessionCode(String professionCodeString) throws Throwable {
    Thread.sleep(1000);/*ww w .j  a  v a2 s .co  m*/
    WebElement professionCode = driver.findElement(By.name("professionCode"));
    Select mySelect = new Select(professionCode);
    mySelect.selectByVisibleText(professionCodeString);
}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectPost(String postString) throws Throwable {
    Thread.sleep(1000);//  w w w .j  av  a 2 s  . co  m
    WebElement post = driver.findElement(By.name("post"));
    Select mySelect = new Select(post);
    mySelect.selectByVisibleText(postString);
}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectIndustry(String industryString) throws Throwable {
    Thread.sleep(1000);// w  w w .  j a  va 2 s .  c  om
    WebElement industry = driver.findElement(By.name("industry"));
    Select mySelect = new Select(industry);
    mySelect.selectByVisibleText(industryString);
}

From source file:cls.ui.model.selenium.loanreview.BusinessEnteringPage.java

public void selectWorkNatureCode(String workNatureCodeString) throws Throwable {
    Thread.sleep(1000);/*from   ww  w.j  a  v a2 s. com*/
    WebElement workNatureCode = driver.findElement(By.name("workNatureCode"));
    Select mySelect = new Select(workNatureCode);
    mySelect.selectByVisibleText(workNatureCodeString);
}