Example usage for org.openqa.selenium By tagName

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

Introduction

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

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:com.coderoad.automation.common.util.old.BasePage.java

License:Open Source License

public String getVersion(Enum<Modules> portal) {
    String response = null;/*from   w w  w  .j  av  a2s . c om*/
    try {
        if (portal == Modules.CONSUMER_MENU) {
            WebElement html = driver.findElement(By.tagName("html"));
            Assert.assertTrue("The page is not displayed.", html != null);
            String selectAll = Keys.chord(Keys.CONTROL, Keys.SHIFT, "v");
            html.sendKeys(selectAll);
            Alert alertVersion = driver.switchTo().alert();
            response = alertVersion.getText().split(":")[1];
            alertVersion.accept();
        } else if (portal == Modules.MOBILE_PORTAL) {
            WebElement element = driver.findElement(By.xpath("//div[contains(@class, 'site-version')]"));
            Actions actions = new Actions(driver);
            Action doubleClick = actions.doubleClick(element).build();
            doubleClick.perform();
            Alert alertVersion = driver.switchTo().alert();
            response = alertVersion.getText();
            alertVersion.accept();
        }

    } catch (Exception e) {
        e.printStackTrace();
        response = null;
    }
    return response;
}

From source file:com.coderoad.automation.common.util.PageUtil.java

License:Open Source License

/**
 * Method to set date in a date picker//from   www  . j a  va 2  s.c  om
 * @author Ruth Chirinos
 * @param driver the WebDriver
 * @param xpathDatePicker the xpath of the datePicker
 * @param vehicleSelectionPage  
 * year  - the year minus 1900.
  * month - the month between 0-11.
  * date  - the day of the month between 1-31.
 * @throws InterruptedException 
 * @throws ParseException 
 */
public static boolean setDateInDatePicker(WebDriver driver, String xpathDatePicker, Date dateRequested)
        throws InterruptedException, ParseException {
    Calendar dateRequestedCalendar = DateUtil.getCalendarForDate(dateRequested);
    LogUtil.log("Date for changing is > "
            + DateUtil.format(dateRequestedCalendar, DateUtil.DATE_MONTH_ABBREVIATION), LogLevel.LOW);
    boolean processOk = false;
    String dateSelectedString = "";
    Date dateSelected = null;

    SimpleDateFormat simpleFormat = new SimpleDateFormat(DateUtil.DATE_MONTH_YEAR_FMT);
    WebElement datePicker = driver.findElement(By.xpath(xpathDatePicker));
    datePicker.click();
    WebElement monthYearElement = driver
            .findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]"));
    WebElement daySelected = driver.findElement(By.xpath("//*[contains(@class, 'x-datepicker-selected')]/a"));
    dateSelectedString = daySelected.getAttribute("innerHTML") + " "
            + monthYearElement.getAttribute("innerHTML");
    dateSelected = simpleFormat.parse(dateSelectedString);

    WebElement pickerPrevEl = driver.findElement(
            By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-prev')]"));
    WebElement pickerNextEl = driver.findElement(
            By.xpath("//div[@class='x-datepicker-header']/a[contains(@class, 'x-datepicker-next')]"));

    //Choosing the year
    while (dateRequested.getYear() < dateSelected.getYear()) {
        pickerPrevEl.click();
        monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]"));
        dateSelectedString = daySelected.getAttribute("innerHTML") + " "
                + monthYearElement.getAttribute("innerHTML");
        dateSelected = simpleFormat.parse(dateSelectedString);
    }

    while (dateRequested.getYear() > dateSelected.getYear()) {
        pickerNextEl.click();
        monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]"));
        dateSelectedString = daySelected.getAttribute("innerHTML") + " "
                + monthYearElement.getAttribute("innerHTML");
        dateSelected = simpleFormat.parse(dateSelectedString);
    }

    //Choosing the months
    while (dateRequested.getMonth() < dateSelected.getMonth()) {
        pickerPrevEl.click();
        monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]"));
        dateSelectedString = daySelected.getAttribute("innerHTML") + " "
                + monthYearElement.getAttribute("innerHTML");
        dateSelected = simpleFormat.parse(dateSelectedString);
    }

    while (dateRequested.getMonth() > dateSelected.getMonth()) {
        pickerNextEl.click();
        monthYearElement = driver.findElement(By.xpath("//div[@class='x-datepicker-month']/div/div/a/span[1]"));
        dateSelectedString = daySelected.getAttribute("innerHTML") + " "
                + monthYearElement.getAttribute("innerHTML");
        dateSelected = simpleFormat.parse(dateSelectedString);
    }

    //Choosing the day      
    WebElement dateWidget = driver.findElement(By.className("x-datepicker-inner"));
    List<WebElement> columns = dateWidget.findElements(By.tagName("td"));
    int aux = 0;

    for (WebElement cell : columns) {
        if (cell.getText().equals(dateRequested.getDate() + "")) {
            processOk = cell.getAttribute("class").contains("x-datepicker-active");
            if (processOk) {
                cell.findElement(By.tagName("a")).click();
                ;
                LogUtil.log("The date was selected.", LogLevel.LOW);
                aux = 1;
                break;
            }
        }
    }

    if (aux == 0) {
        LogUtil.log("The date selected is not enabled.", LogLevel.LOW);
    }
    return processOk;
}

From source file:com.cognifide.bdd.demo.po.touchui.CarouselComponent.java

License:Apache License

public String getAnchorHref(int itemIndex) {
    return items.get(itemIndex).findElement(By.tagName("a")).getAttribute(HtmlTags.Attributes.HREF);
}

From source file:com.cognifide.qa.bb.aem.core.component.dialog.DialogFieldRetrieverImpl.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  ww  . j a v a  2 s  .c o  m*/
 */
@Override
public DialogField getDialogField(WebElement parentElement, String type) {
    WebElement scope = parentElement.findElement(By.tagName("input"));
    return getFieldObject(scope, type);
}

From source file:com.cognifide.qa.bb.aem.dialog.classic.field.AemRichText.java

License:Apache License

private void switchToTextArea() {
    boolean isRichtextDisabled = isRichtextDisabled();
    if (StringUtils.isEmpty(frameName)) {
        frameName = currentScope.findElement(By.tagName("iframe")).getAttribute("name");
    }/* w  w w.  j a  v a 2s  . com*/
    frameSwitcher.switchTo("/$cq/" + frameName);
    if (isRichtextDisabled) {
        webDriver.switchTo().activeElement().click();
    }
}

From source file:com.cognifide.qa.bb.aem.touch.pageobjects.touchui.DialogConfigurer.java

License:Apache License

/**
 * Find the dialog input field of given type within a parent WebElement.
 *
 * @param parentElement parent element from which DialogField will be retrieved.
 * @param type          of the requested field.
 * @return DialogField of the given type based on the provided info.
 *//*w  w w .  j  a  v  a2s  .  c o  m*/
public DialogField getDialogField(WebElement parentElement, String type) {
    WebElement scope = parentElement.findElement(By.tagName("input"));
    return getFieldObject(scope, type);
}

From source file:com.cognifide.qa.bb.aem.ui.wcm.windows.CreateSiteWindow.java

License:Apache License

/**
 * Selects chapters on Chapters view/*from   w  ww .  jav a2 s . c o m*/
 *
 * @param chapters list of languages
 * @return this CreateSiteWindow
 */
public CreateSiteWindow selectChapters(List<String> chapters) {
    List<WebElement> items = currentWindow
            .findElements(By.cssSelector(".cq-msm_58chapterPages .x-form-check-wrap"));
    for (WebElement item : items) {
        WebElement label = item.findElement(By.tagName("label"));
        if (!chapters.contains(label.getText())) {
            item.findElement(By.tagName("input")).click();
        }
    }
    return this;
}

From source file:com.cognifide.qa.bb.test.actions.BobcatActionsTest.java

License:Apache License

@Before
public void setUp() {
    webDriver.get(PageUtils.buildTestPageUrl(this.getClass()));
    inputElement = webDriver.findElement(By.tagName(INPUT_TAG_NAME));
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldAnswerTrueWhenElementIsNotPresent() {
    //given/* ww  w . ja v a 2 s  . c  o m*/
    By by = By.tagName(NOT_PRESENT_TAG);

    //when
    boolean actual = waitFor(CommonExpectedConditions.elementNotPresent(by));

    //then
    assertThat(actual).as("check if element is not present").isTrue();
}

From source file:com.cognifide.qa.bb.test.expectedconditions.CommonExpectedConditionsTest.java

License:Apache License

@Test
public void shouldThrowExceptionWhenElementIsPresent() {
    //given//from  www .  j av a2s.c  o m
    exception.expect(TimeoutException.class);
    By by = By.tagName(PRESENT_TAG);

    //when
    waitFor(CommonExpectedConditions.elementNotPresent(by));
}