List of usage examples for org.openqa.selenium By tagName
public static By tagName(String tagName)
From source file:com.elastica.webelements.PageObject.java
License:Apache License
private void populateAndCapturePageSnapshot() { try {/*from w ww . j a v a 2s. co m*/ setTitle(driver.getTitle()); /* * IE driver will get timeout frequently when calling getText Logs: * Line 10943: INFO | jvm 1 | 2013/06/30 17:57:56 | 17:57:56.514 * INFO - Executing: [find element: By.tagName: body] at URL: * /session/2c3f9f68-d782-4162-9297-c628f31a50d2/element) Line * 10944: INFO | jvm 1 | 2013/06/30 17:57:56 | 17:57:56.561 INFO - * Done: /session/2c3f9f68-d782-4162-9297-c628f31a50d2/element Line * 10945: INFO | jvm 1 | 2013/06/30 17:57:56 | 17:57:56.561 INFO - * Executing: [get text: 6 org.openqa.selenium.support.events. * EventFiringWebDriver$EventFiringWebElement@96812584] at URL: * /session/2c3f9f68-d782-4162-9297-c628f31a50d2/element/6/text) * Line 12020: INFO | jvm 1 | 2013/06/30 18:02:12 | 18:02:12.105 * WARN - Session 2c3f9f68-d782-4162-9297-c628f31a50d2 deleted due * to in-browser timeout. Terminating driver with DeleteSession * since it does not support Killable, the driver in question does * not support selenium-server timeouts fully * * so use htmlsource to replace gettext. */ htmlSource = driver.getPageSource(); try { bodyText = driver.findElement(By.tagName("body")).getText(); } catch (StaleElementReferenceException ignore) { logger.warn("StaleElementReferenceException got in populateAndCapturePageSnapshot"); bodyText = driver.findElement(By.tagName("body")).getText(); } } catch (UnreachableBrowserException e) { // throw // UnreachableBrowserException throw new WebDriverException(e); } catch (WebDriverException e) { throw e; } capturePageSnapshot(); }
From source file:com.elastica.webelements.SelectList.java
License:Apache License
protected void findElement() { driver = WebUIDriver.getWebDriver(); element = driver.findElement(this.getBy()); try {/*from w ww . j a v a2 s .c o m*/ select = getNewSelectElement(element); options = select.getOptions(); } catch (UnexpectedTagNameException e) { if (element.getTagName().equalsIgnoreCase("ul")) { options = element.findElements(By.tagName("li")); } } }
From source file:com.elastica.webelements.SelectList.java
License:Apache License
public void init() { super.init(); try {/*from w ww .ja v a 2 s . co m*/ select = getNewSelectElement(element); options = select.getOptions(); } catch (UnexpectedTagNameException e) { if (element.getTagName().equalsIgnoreCase("ul")) { options = element.findElements(By.tagName("li")); } } }
From source file:com.elastica.webelements.Table.java
License:Apache License
public void findElement() { super.findElement(); try {// w w w . j av a2 s . com rows = element.findElements(By.tagName("tr")); } catch (NotFoundException e) { } }
From source file:com.elastica.webelements.Table.java
License:Apache License
public int getColumnCount() { if (rows == null) { findElement();/*from w w w . ja va 2s . c om*/ } // Need to check whether rows is null AND whether or not the list of rows is empty if (rows != null && !rows.isEmpty()) { try { columns = rows.get(0).findElements(By.tagName("td")); } catch (NotFoundException e) { } if (columns == null || columns.size() == 0) { try { if (rows.size() > 1) { columns = rows.get(1).findElements(By.tagName("td")); } else { columns = rows.get(0).findElements(By.tagName("th")); } } catch (NotFoundException e) { } } } if (columns != null) { return columns.size(); } return 0; }
From source file:com.elastica.webelements.Table.java
License:Apache License
/** * Get table cell content.//from w w w. j a va 2s . c o m * * @param row Starts from 1 * @param column Starts from 1 */ public String getContent(final int row, final int column) { if (rows == null) { findElement(); } if (rows != null && !rows.isEmpty()) { try { columns = rows.get(row - 1).findElements(By.tagName("td")); } catch (NotFoundException e) { } if (columns == null || columns.size() == 0) { try { columns = rows.get(row - 1).findElements(By.tagName("th")); } catch (NotFoundException e) { } } return columns.get(column - 1).getText(); } return null; }
From source file:com.epam.jdi.uitests.mobile.appium.driver.WebDriverByUtils.java
License:Open Source License
public static By getByFromString(String stringLocator) { if (stringLocator == null || stringLocator.equals("")) throw new RuntimeException("Can't get By locator from string empty or null string"); String[] split = stringLocator.split("(^=)*=.*"); if (split.length == 1) return By.cssSelector(split[0]); switch (split[0]) { case "css": return By.cssSelector(split[1]); case "xpath": return By.xpath(split[1]); case "class": return By.className(split[1]); case "name": return By.name(split[1]); case "id": return By.id(split[1]); case "tag": return By.tagName(split[1]); case "link": return By.partialLinkText(split[1]); default:/* w ww . ja va 2s . c om*/ throw new RuntimeException(String.format( "Can't get By locator from string: %s. Bad suffix: %s. (available: css, xpath, class, id, name, link, tag)", stringLocator, split[0])); } }
From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.BaseSelector.java
License:Open Source License
protected void selectAction(String name) { if (!hasLocator() && allLabels() == null) throw exception("Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found", name); if (hasLocator() && getLocator().toString().contains("%s")) { new Clickable(fillByTemplate(getLocator(), name)).click(); return;/*from w ww .ja v a2 s . co m*/ } if (allLabels() != null) { selectFromList(allLabels().avatar.searchAll().getElements(), name); return; } List<WebElement> elements = getAvatar().searchAll().getElements(); WebElement element = elements.get(0); if (elements.size() == 1 && element.getTagName().equals("select")) if (getSelector().getOptions().size() > 0) { getSelector().selectByVisibleText(name); return; } else throw exception("<select> tag has no <option> tags. Please Clarify element locator (%s)", this); if (elements.size() == 1 && element.getTagName().equals("ul")) elements = element.findElements(By.tagName("li")); selectFromList(elements, name); }
From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.BaseSelector.java
License:Open Source License
protected void selectAction(int num) { if (!hasLocator() && allLabels() == null) throw exception("Can't find option '%s'. No optionsNamesLocator and allLabelsLocator found", num); if (allLabels() != null) { selectFromList(allLabels().getWebElements(), num); return;//from w ww.j a v a 2s. c o m } if (getLocator().toString().contains("%s")) { new Clickable(fillByTemplate(getLocator(), num)).click(); return; } List<WebElement> elements = getAvatar().searchAll().getElements(); WebElement element = elements.get(0); if (elements.size() == 1 && element.getTagName().equals("select")) if (getSelector().getOptions().size() > 0) { getSelector().selectByIndex(num - 1); return; } else throw exception("<select> tag has no <option> tags. Please Clarify element locator (%s)", this); if (elements.size() == 1 && element.getTagName().equals("ul")) elements = element.findElements(By.tagName("li")); selectFromList(elements, num); }
From source file:com.epam.jdi.uitests.mobile.appium.elements.complex.BaseSelector.java
License:Open Source License
public List<WebElement> getElementsFromTag() { List<WebElement> elements; try {/*from w ww . j a v a 2 s . c om*/ elements = getAvatar().searchAll().getElements(); } catch (Exception | Error ex) { return new ArrayList<>(); } WebElement element = elements.get(0); if (elements.size() == 1) switch (element.getTagName()) { case "select": return getSelector().getOptions(); case "ul": return element.findElements(By.tagName("li")); } return elements; }