Example usage for org.openqa.selenium WebDriver getTitle

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

Introduction

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

Prototype

String getTitle();

Source Link

Document

Get the title of the current page.

Usage

From source file:com.ibm.sbt.automation.core.environment.TestEnvironment.java

License:Open Source License

/**
 * this method tests for error pages from which the test cannot recover so
 * that instead of waiting the full timeout while testing for a until() to
 * happen we can fail the test early//from   w  w  w.  j  a v a 2  s.  c  om
 */
private void failIfPageCrashed(WebDriver webDriver) {
    // TODO: populate with more conditions as we find them
    String text = getPageObject(webDriver).getText();
    if (webDriver.getTitle().contains("Apache Tomcat") && webDriver.getTitle().contains("Error report")) {
        fail(text);
    }
    if (text.startsWith("Error, unable to load snippet: ")) {
        fail(text);
    }
    if (text.contains("Unrecognized SSL message, plaintext connection?")) {
        fail("Cannot reach the quickstart image, probably firewall issues\n" + text);
    }
    if (text.contains("oauth_consumer_missing_subscription")) {
        fail("Missing OAuth configuration -> 'oauth_consumer_missing_subscription'\n" + text);
    }
    if (text.contains("Your account has been expired or suspended.")) {
        fail("Smartcloud credential probably expired\n" + text);
    }
    if (text.contains("Your account has expired or has been suspended.")) {
        fail("Smartcloud credential probably expired\n" + text);
    }
}

From source file:com.ibm.watson.movieapp.dialog.fvt.testcases.selenium.BaseGUI_IT.java

License:Open Source License

/**
 *<ul>//from   www.j  av  a2 s . com
 *<li><B>Info: </B>Test the terms and conditions link on the landing page</li>
 *<li><B>Step: </B>Navigate to landing page</li>
 *<li><B>Verify: </B>Validate the terms and condition link is present</li>
 *<li><B>Step: </B>Select the terms and condition link</li>
 *<li><B>Verify: </B>Validate that the page navigated to title equals the expected title</li>
 *</ul>
 */
@Test
public void termsConditions() {

    RestAPI api = RestAPI.getAPI();
    String expectedTitle = api.getJSONElem(COMMON, "terms");
    String title = "";

    Driver test = new Driver();
    WebDriver driver = test.getInstance();
    rule.setDriver(driver);

    MovieUI ui = test.getGui(driver);

    assertTrue("ERROR: Terms of service Link is not present", ui.fluentWaitPresent(MovieUI.termsServiceLink));

    logger.info("INFO: Select Terms and Conditions link");
    WebElement link = ui.findElement(MovieUI.termsServiceLink);
    link.click();

    title = driver.getTitle();

    logger.info("INFO: Title of Terms and Conditions page - " + title);

    //Validate that the title of page for Terms of Use matches expected
    assertTrue(
            "ERROR: Title of page - " + title
                    + " does not match expected title of the Terms and Conditions page - " + expectedTitle,
            title.contains(expectedTitle));
}

From source file:com.ibm.watson.movieapp.dialog.fvt.testcases.selenium.BaseGUI_IT.java

License:Open Source License

/**
 *<ul>//w  ww  .java  2s.co  m
 *<li><B>Info: </B>Test the privacy link on the landing page</li>
 *<li><B>Step: </B>Navigate to landing page</li>
 *<li><B>Verify: </B>Validate the privacy link is present</li>
 *<li><B>Step: </B>Select the privacy link</li>
 *<li><B>Verify: </B>Validate that the page navigated to title equals the expected title</li>
 *</ul>
 */
@Test
public void privacy() {

    RestAPI api = RestAPI.getAPI();
    String expectedTitle = api.getJSONElem(COMMON, "privacy");
    String title = "";

    Driver test = new Driver();
    WebDriver driver = test.getInstance();
    rule.setDriver(driver);

    MovieUI ui = test.getGui(driver);

    assertTrue("ERROR: Privacy Link is not present", ui.fluentWaitPresent(MovieUI.privacyLink));

    logger.info("INFO: Select Privacy link");
    WebElement link = ui.findElement(MovieUI.privacyLink);
    link.click();

    title = driver.getTitle();

    logger.info("INFO: Title of IBM Privacy page - " + title);

    //Validate that the title of page for IBM Privacy matches expected
    assertTrue("ERROR: Title of page - " + title + " does not match expected title of the IBM Privacy page - "
            + expectedTitle, title.contains(expectedTitle));
}

From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPage.java

public static void check(WebDriver driver, AbnormalAdvertiserInfo1 aainfo) {
    String title = driver.getTitle();
    if (!title.equals("")) {
        ScreenshotandAssert.screenandasserttitle(driver, "", "");
    } else {//  w w  w  .ja  v a2s.  c om
        String adname = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]"))
                .getText();
        if (!adname.equals(aainfo.getAdnamereminder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAdnamereminder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]"));
        }
        String comname = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[2]/td[3]/span[2]"))
                .getText();
        if (!comname.equals(aainfo.getAdnamereminder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAdnamereminder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[2]/td[3]/span[2]"));
        }
        String url = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[2]"))
                .getText();
        String urlex = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[4]"))
                .getText();
        if (!url.equals(aainfo.getUrlremainder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getUrlremainder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[2]"));
        }
        if (!urlex.equals(aainfo.getUrlexample())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getUrlexample(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[4]"));
        }
        String contact = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[7]/td[3]/span[2]"))
                .getText();
        if (!contact.equals(aainfo.getContactremainder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getContactremainder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[7]/td[3]/span[2]"));
        }
        String email = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[8]/td[3]/span[2]"))
                .getText();
        if (!email.equals(aainfo.getEmailremainder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getEmailremainder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[8]/td[3]/span[2]"));
        }
        String aptitude = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[10]/td[3]/span[2]"))
                .getText();
        if (!aptitude.equals(aainfo.getAptituderemainder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAptituderemainder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[10]/td[3]/span[2]"));
        }
    }
}

From source file:com.ipinyou.webpage.abnormalwebpage.AbnormalAdvertiserPageName.java

public static void check(WebDriver driver, AbnormalAdvertiserNameInfo aainfo) {
    String title = driver.getTitle();
    if (!title.equals("")) {
        ScreenshotandAssert.screenandasserttitle(driver, "", "");
    } else {/*  ww w .j  a  v a 2 s . c o  m*/
        String adname = driver
                .findElement(
                        By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]"))
                .getText();
        if (!adname.equals(aainfo.getAdnamereminder())) {
            ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAdnamereminder(),
                    By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[1]/td[3]/span[2]"));
        }

        /*String comname =driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[2]/td[3]/span[2]")).getText();
        if(!comname.equals(aainfo.getAdnamereminder())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAdnamereminder(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[2]/td[3]/span[2]"));
        }
        String url = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[2]")).getText();
        String urlex = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[4]")).getText();
        if(!url.equals(aainfo.getUrlremainder())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getUrlremainder(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[2]"));
        }
        if(!urlex.equals(aainfo.getUrlexample())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getUrlexample(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[5]/td[3]/span[4]"));
        }
        String contact = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[7]/td[3]/span[2]")).getText();
        if(!contact.equals(aainfo.getContactremainder())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getContactremainder(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[7]/td[3]/span[2]"));
        }
        String email = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[8]/td[3]/span[2]")).getText();
        if(!email.equals(aainfo.getEmailremainder())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getEmailremainder(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[8]/td[3]/span[2]"));
        }
        String aptitude = driver.findElement(By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[10]/td[3]/span[2]")).getText();
        if(!aptitude.equals(aainfo.getAptituderemainder())){
           ScreenshotandAssert.screenandasserttext(driver, "", aainfo.getAptituderemainder(), By.xpath("//*[@id='advertiser_form']/div[1]/div[2]/table/tbody/tr[10]/td[3]/span[2]"));
        }*/
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void VERIFYTHIS(WebDriver driver, String fieldText, String value) {
    //Used to verify the text in any specific Loctor or Message
    //<XPH or LNK or IDI or TXT><Locator> or MSG in fieldText 
    //Text or Message to be verified in Value
    try {// www  .  j  a  v a2s .c o m
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS);
        String f = fieldText;
        String val = value;
        String locatorType = f.substring(0, 3);
        String locatorValue = f.substring(3, f.length());
        if (locatorType.equalsIgnoreCase("XPH")) {
            System.out.println(driver.findElement(By.xpath(locatorValue)).getText());
            if (driver.findElement(By.xpath(locatorValue)).getText().equalsIgnoreCase(val))
                resultDetails.setFlag(true);
        } else if (locatorType.equalsIgnoreCase("LNK")) {

            if (driver.findElement(By.linkText(locatorValue)).getText().equalsIgnoreCase(val))
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) {

            if (driver.findElement(By.id(locatorValue)).getText().equalsIgnoreCase(val))
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("MSG")) {

            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.findElement(By.xpath("//*[contains(text(),'" + val + "')]")).isDisplayed()) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        }

        else if (locatorType.equalsIgnoreCase("TTL")) {
            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.getTitle().equalsIgnoreCase(val)) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("URL")) {
            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.getCurrentUrl().equalsIgnoreCase(val)) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        }
    }

    catch (Exception e) {
        e.printStackTrace();
        resultDetails.setErrorMessage(
                fieldText + " Text is not matching with that of the locator (or) the locator not found");
        resultDetails.setFlag(false);
    }

}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static void selectWindow(WebDriver webDriver, String windowID) {
    Set<String> windowHandles = webDriver.getWindowHandles();

    if (windowID.equals("name=undefined")) {
        String title = webDriver.getTitle();

        for (String windowHandle : windowHandles) {
            WebDriver.TargetLocator targetLocator = webDriver.switchTo();

            targetLocator.window(windowHandle);

            if (!title.equals(webDriver.getTitle())) {
                return;
            }//from   w ww.ja  va 2s . co  m
        }

        TestCase.fail("Unable to find the window ID \"" + windowID + "\"");
    } else if (windowID.equals("null")) {
        WebDriver.TargetLocator targetLocator = webDriver.switchTo();

        targetLocator.window(_defaultWindowHandle);
    } else {
        String targetWindowTitle = windowID;

        if (targetWindowTitle.startsWith("title=")) {
            targetWindowTitle = targetWindowTitle.substring(6);
        }

        for (String windowHandle : windowHandles) {
            WebDriver.TargetLocator targetLocator = webDriver.switchTo();

            targetLocator.window(windowHandle);

            if (targetWindowTitle.equals(webDriver.getTitle())) {
                return;
            }
        }

        TestCase.fail("Unable to find the window ID \"" + windowID + "\"");
    }
}

From source file:com.liferay.faces.test.util.TesterBase.java

License:Open Source License

public void signIn(WebDriver browser, WebElement user, WebElement pass, WebElement button, WebElement text,
        String textXpath, String u, String p) throws Exception {

    java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);

    logger.log(Level.INFO, "browser.navigate().to(" + signInUrl + ")");
    browser.navigate().to(signInUrl);//w  ww.ja v  a 2  s  .com
    logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ...");

    if (browser.getTitle().contains("Status")) {
        logger.log(Level.INFO, "welcome-theme installed ...");
        String welcomeSignInUrl = signInUrl.replace("home", "welcome");
        logger.log(Level.INFO, "browser.navigate().to(" + welcomeSignInUrl + ")");
        browser.navigate().to(welcomeSignInUrl);
        logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ...");
    } else {
        logger.log(Level.INFO, "no welcome-theme, no problem ...");
    }

    if (isThere(browser, "//div[contains(text()[2],'was not found')]")) {

        // attempt to go to a Bridge Demos to get to the login page
        logger.log(Level.INFO, "Attempting to go to a Bridge Demos to get to the login page ...");
        String bridgeDemosSignInUrl = baseUrl + "/group/bridge-demos/";
        logger.log(Level.INFO, "browser.navigate().to(" + bridgeDemosSignInUrl + ")");
        browser.navigate().to(bridgeDemosSignInUrl);
        logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle() + " before signing in ...");

        waitForElement(browser, emailFieldXpath);
        user.clear();
        user.sendKeys(u);
        pass.clear();
        pass.sendKeys(p);
        button.click();

        waitForElement(browser, "//span[contains(text(),'Bridge Demos')]");

        return;
    }

    user.clear();
    user.sendKeys(u);
    pass.clear();
    pass.sendKeys(p);
    button.click();
    logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle()
            + " after clicking the sign in button.   Now waiting ...");
    waitForElement(browser, textXpath);
    logger.log(Level.INFO, text.getText());

}

From source file:com.mediamelon.UserActions.java

void addAccount(WebDriver driver, List<String> formData) {
    //Verify if the user is logged in as Super User to create a new account. 
    //If not, display message and return

    //Verify if the user is logged in
    String pageTitle = driver.getTitle();
    Assert.assertEquals(pageTitle, "MediaMelon - Home");
    String fullName = driver.findElement(By.xpath("//div[@class='row data']/div/div[1]/p[2]")).getText();
    String role = driver.findElement(By.xpath("//div[@class='row data']/div/div[3]/p[2]")).getText();

    if (fullName.equalsIgnoreCase("Super User") && role.equalsIgnoreCase("admin")) {

        System.out.println("List of Accounts is displayed");
        //expand the settings menu option and click on Account Management
        List<WebElement> dropDownOptions = driver.findElements(By.className("dropdown-toggle"));
        dropDownOptions.get(0).click();/*from  w  ww.  j a  va 2 s .  co  m*/
        WebElement accountManagement = driver.findElement(By.cssSelector(".dropdown-menu.dropdown-admin"));
        Assert.assertTrue(accountManagement.isDisplayed());
        accountManagement.findElement(By.linkText("Account Management")).click();

        Assert.assertEquals(driver.getTitle(), "List of Accounts");

        WebElement accountsTable = driver.findElement(By.xpath("//div[@class='row well']/table"));
        Assert.assertTrue(accountsTable.isDisplayed());
        WebElement addAccountBtn = driver.findElement(By.cssSelector(".btn.btn-primary"));

        System.out.println("Clicking on Add a new account button");
        Assert.assertEquals(addAccountBtn.getText(), "Add a new Account");
        addAccountBtn.click();

        //Fill account add form
        WebElement accountForm = driver.findElement(By.tagName("form"));
        Assert.assertTrue(accountForm.isDisplayed());
        System.out.println(accountForm.getAttribute("action"));

        accountForm.findElement(By.id("companyName")).sendKeys(formData.get(0));
        accountForm.findElement(By.id("companyWebsite")).sendKeys(formData.get(1));
        accountForm.findElement(By.id("adminName")).sendKeys(formData.get(2));
        accountForm.findElement(By.id("adminEmail")).sendKeys(formData.get(3));

        Select licenseType = new Select(driver.findElement(By.id("licenseType")));
        licenseType.selectByVisibleText(formData.get(4));

        Select services = new Select(driver.findElement(By.id("services")));
        String requiredServices = formData.get(5);
        String multipleSel[] = formData.get(5).split(",");

        if (requiredServices.equalsIgnoreCase("All")) {
            services.selectByIndex(0);
            services.selectByIndex(1);
            services.selectByIndex(2);
        } else if (multipleSel.length > 1) {
            for (int i = 0; i < multipleSel.length; i++)
                services.selectByVisibleText(multipleSel[i]);
        } else
            services.selectByVisibleText(requiredServices);

        accountForm.findElement(By.id("companyName")).sendKeys(formData.get(5));
        //submit the form
        System.out.println("Submitting the form");
        accountForm.findElement(By.cssSelector("button[value='submit']")).click();
        System.out.println("clicked on submit button");

        accountsTable = driver.findElement(By.cssSelector("table.table-striped.table-hover.table-bordered"));
        Assert.assertTrue(accountsTable.isDisplayed());
        System.out.println("form submitted sucessfully");

        //Verify the presence of newly created account in the list of accounts
        System.out.println("Verifying if the newly created account is present in the list");
        String tableData = accountsTable.getText();
        System.out.println("Table Data: " + tableData);
        //findElement(By.xpath(".//*[@class='studyResultsId']/div/table/tbody/tr/td")).getText();

        //Retrieving the data from the Td of table in to a string
        if (tableData.contains(formData.get(5))) {
            System.out.println("contains newly created account");
        } else {
            System.out.println("does not contains newly created account");
        }
    } else
        System.out.println("User not authorized to create an account");

}

From source file:com.mycompany.mavenproject1.main.java

public static void main(String[] args) throws InterruptedException {
    String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe";
    Map<String, Object> prefs = new HashMap<String, Object>();
    prefs.put("profile.default_content_setting_values.notifications", 2);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);

    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver(options);
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    WebDriverWait wait = new WebDriverWait(driver, 10);
    driver.get("https://www.facebook.com");

    String actualTitle = driver.getTitle();

    if (actualTitle.contentEquals("Facebook - Log In or Sign Up")) {
        driver.findElement(By.id("email")).sendKeys("");
        driver.findElement(By.id("pass")).sendKeys("");
        TimeUnit.SECONDS.sleep(1);
        driver.findElement(By.id("u_0_o")).submit();
        System.out.println("Test Passed!");
    } else {// ww  w. j a va2 s .  co m
        System.out.println("test is failed");
        driver.close();
        return;
    }
    int x = 0;
    while (x < 2) {
        jse.executeScript("scroll(0, 100000);");

        x++;
        TimeUnit.SECONDS.sleep(1);

    }

    try {

        jse.executeScript("scroll(0, 0);");
        List<WebElement> click = driver.findElements(By.xpath("//*[@class='comment_link _5yxe']"));

        List<WebElement> Names = driver.findElements(By.xpath("//*[@class=' UFICommentActorName']"));

        System.out.println(Names.size() + "This is how many elements in Names");

        List<WebElement> comments = driver.findElements(By.xpath("//*[@class='UFICommentBody']"));

        for (WebElement el : click) {
            if (!el.getText().isEmpty())

            {
                //System.out.println(el.getText()); 
                System.out.println("Attempting to click " + el.getText());
                jse.executeScript(
                        "return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", el);
                TimeUnit.MILLISECONDS.sleep(500);
                el.click();

            } else {
                System.out.println("This is what we got from the web element\n");
                System.out.println(el.getText());

            }
        }

        jse.executeScript("int x = 0;" + "scroll(0, 0);");
        TimeUnit.SECONDS.sleep(1);
        for (WebElement el : Names) {

            jse.executeScript(
                    "return arguments[0].scrollIntoView(0, document.documentElement.scrollHeight-10);", el);
            TimeUnit.SECONDS.sleep(1);
            System.out.println(el.getText());

        }
    }

    catch (NoSuchElementException e) {
        System.err.println("too slow on the scrolling");

    }

}