Java Code Examples for org.openqa.selenium.WebElement#getTagName()

The following examples show how to use org.openqa.selenium.WebElement#getTagName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CommonMethods.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
public HashMap<String, String> getCellValue(WebElement Element, int tr,
        int td) {
    int rowCounter = 0;
    int colCounter = 0;
    String rowKey = null;
    String colKey = null;
    HashMap<String, String> HashTable = new HashMap<>();

    String strObj = Data;
    List<WebElement> tableList = Element.findElements(By
            .cssSelector("div[class='" + strObj + "'] tr td"));
    for (WebElement listIterator : tableList) {
        String TagName = listIterator.getTagName();
        if (TagName.equals("tr")) {
            rowKey = "R" + rowCounter++;
        }
        if (TagName.equals("td")) {
            colKey = "C" + colCounter++;
        }
        HashTable.put(rowKey + colKey, listIterator.getText());
    }
    return HashTable;
}
 
Example 2
Source File: Command.java    From frameworkium-core with Apache License 2.0 6 votes vote down vote up
private void setUsingAndValue(WebElement element) {
    // TODO: Improve this. Use hacky solution in LoggingListener?
    if (Driver.isNative()) {
        this.using = "n/a";
        this.value = "n/a";
    } else {
        if (StringUtils.isNotBlank(element.getAttribute("id"))) {
            this.using = "id";
            this.value = element.getAttribute("id");
        } else if (!(element.getText()).isEmpty()) {
            this.using = "linkText";
            this.value = element.getText();
        } else if (!element.getTagName().isEmpty()) {
            this.using = "css";
            this.value = element.getTagName() + "."
                    + element.getAttribute("class").replace(" ", ".");
        } else {
            // must be something weird
            this.using = "n/a";
            this.value = "n/a";
        }
    }
}
 
Example 3
Source File: RichFacesTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 6 votes vote down vote up
protected boolean hasRichFacesAjax(WebElement element) {
    if (element == null) {
        return false;
    }
    boolean result = isAjaxEventPresent(element);
    if (!result) {
        String tagName = element.getTagName();
        if ("label".equalsIgnoreCase(tagName)) {
            WebElement labelTarget = getSeleniumHelper().getLabelledElement(element);
            if (labelTarget != null) {
                result = isAjaxEventPresent(labelTarget);
            }
        }
    }
    if (result) {
        // store current URL so we can check against it later when waiting for Ajax
        storeLocationBeforeAction();
    }
    return result;
}
 
Example 4
Source File: TCKLiferayTestDriver.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected void click(WebElement wel) {

	   boolean sennaJS = true;
	   String url = null;

	   if (wel != null) {
          String tagName = wel.getTagName();

	      if ("a".equals(tagName)) {
             url = wel.getAttribute("href");
             sennaJS = !url.contains("v3headerportlettests") && !url.contains("v3portlethubtests");
          }
	   }

	   if (sennaJS) {
          wel.click();
       } else {
          driver.get(url);
	   }
   }
 
Example 5
Source File: EncapsulateOperation.java    From LuckyFrameClient with GNU Affero General Public License v3.0 5 votes vote down vote up
public static String getOperation(WebDriver wd, WebElement we, String operation, String value) {
    String result = "";
    // ��ȡ������
    switch (operation) {
        case "gettext":
            result = "��ȡ����ֵ�ǡ�" + we.getText() + "��";
            LogUtil.APP.info("getText��ȡ����text����...��text����ֵ:{}��",result);
            break; // ��ȡ���������
        case "gettagname":
            result = "��ȡ����ֵ�ǡ�" + we.getTagName() + "��";
            LogUtil.APP.info("getTagName��ȡ����tagname����...��tagname����ֵ:{}��",result);
            break;
        case "getattribute":
            result = "��ȡ����ֵ�ǡ�" + we.getAttribute(value) + "��";
            LogUtil.APP.info("getAttribute��ȡ����{}������...��{}����ֵ:{}��",value,value,result);
            break;
        case "getcssvalue":
            result = "��ȡ����ֵ�ǡ�" + we.getCssValue(value) + "��";
            LogUtil.APP.info("getCssValue��ȡ����{}������...��{}����ֵ:{}��",value,value,result);
            break;
        case "getcaptcha":
            result = "��ȡ����ֵ�ǡ�" + Ocr.getCAPTCHA(wd, we) + "��";
            LogUtil.APP.info("getcaptcha��ȡ��֤��...����֤��ֵ:{}��",result);
            break;
        default:
            break;
    }
    return result;
}
 
Example 6
Source File: SeleniumMultiValueEditor.java    From phoenix.webui.framework with Apache License 2.0 5 votes vote down vote up
@Override
public void setValue(Element ele, Object value)
{
    ElementsSearchStrategy<WebElement> strategy = searchStrategyUtils.findElementsStrategy(WebElement.class, ele);
    
    List<WebElement> eleList = strategy.searchAll(ele);
    
    for(int i = 0; i < eleList.size(); i++)
    {
        WebElement webEle = eleList.get(i);
        String tagName = webEle.getTagName();
        String text = webEle.getText();
        
        String attrName = null;
        String attrValue = null;
        
        if(!webEle.isDisplayed())
        {
            continue;
        }
        
        if(filter.filter(tagName, attrName, attrValue, text))
        {
            webEle.sendKeys(value.toString());
        }
    }
}
 
Example 7
Source File: SeleniumElement.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String _getValue()
{
  WebElement currentElement = getElement();

  if (currentElement.getTagName() == null)
    return null;

  String returnValue = null;
  switch (currentElement.getTagName().toUpperCase())
  {
  case "IMG":
    returnValue = currentElement.getAttribute("src");
    break;

  case "INPUT":
    returnValue = currentElement.getAttribute("value");
    break;

  case "SELECT":
    returnValue = new Select(currentElement).getFirstSelectedOption().getText();
    break;

  case "UIATEXTFIELD":
    returnValue = currentElement.getAttribute("value");
    break;

  case "ANDROID.WIDGET.EDITTEXT":
    returnValue = currentElement.getAttribute("text");
    break;

  default:
    returnValue = currentElement.getText();
    break;
  }

  return returnValue;
}
 
Example 8
Source File: AdfComponent.java    From adf-selenium with Apache License 2.0 5 votes vote down vote up
protected <T extends AdfComponent> T findSubIdComponent(String subid) {
    final String subClientId = (String) executeScript(JS_FIND_SUBID_CLIENTID, getClientId(), subid);
    if (subClientId == null) {
        return null;
    }
    if (getClientId().equals(subClientId)) {
        WebElement elem = findSubIdElement(subid);
        throw new SubIdNotFoundException("subid " + subid + " for " + getElement() +
                                         " does not point to a component but to sub-element " +
                                         (elem == null ? "unknown" : elem.getTagName()));
    }
    return AdfComponent.forClientId(driver, subClientId);
}
 
Example 9
Source File: BrowserTest.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
protected boolean clear(WebElement element) {
    boolean result = false;
    String tagName = element.getTagName();
    if ("input".equalsIgnoreCase(tagName) || "textarea".equalsIgnoreCase(tagName)) {
        element.clear();
        result = true;
    }
    return result;
}
 
Example 10
Source File: Select.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not,
 * then an UnexpectedTagNameException is thrown.
 *
 * @param element SELECT element to wrap
 * @throws UnexpectedTagNameException when element is not a SELECT
 */
public Select(WebElement element) {
  String tagName = element.getTagName();

  if (null == tagName || !"select".equals(tagName.toLowerCase())) {
    throw new UnexpectedTagNameException("select", tagName);
  }

  this.element = element;

  String value = element.getAttribute("multiple");

  // The atoms normalize the returned value, but check for "false"
  isMulti = (value != null && !"false".equals(value));
}
 
Example 11
Source File: Type.java    From selenium with Apache License 2.0 5 votes vote down vote up
@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
  alertOverride.replaceAlertMethod(driver);

  if (state.controlKeyDown || state.altKeyDown || state.metaKeyDown)
    throw new SeleniumException(
        "type not supported immediately after call to controlKeyDown() or altKeyDown() or metaKeyDown()");

  String valueToUse = state.shiftKeyDown ? value.toUpperCase() : value;

  WebElement element = finder.findElement(driver, locator);

  String tagName = element.getTagName();
  String elementType = element.getAttribute("type");
  if ("input".equals(tagName.toLowerCase()) &&
      elementType != null && "file".equals(elementType.toLowerCase())) {
    log.warning("You should be using attachFile to set the value of a file input element");
    element.sendKeys(valueToUse);
    return null;
  }

  if (!"input".equals(tagName.toLowerCase())) {
    if (driver instanceof JavascriptExecutor) {
      ((JavascriptExecutor) driver).executeScript("arguments[0].value = '';", element);
    }
    element.sendKeys(valueToUse);
    return null;
  }

  if (driver instanceof JavascriptExecutor) {
    js.executeScript(driver, type, element, valueToUse);
  } else {
    element.clear();
    element.sendKeys(valueToUse);
  }

  return null;
}
 
Example 12
Source File: WebDriverService.java    From cerberus-source with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getValueFromHTML(Session session, Identifier identifier) {
    AnswerItem answer = this.getSeleniumElement(session, identifier, false, false);
    String result = null;
    if (answer.isCodeEquals(MessageEventEnum.ACTION_SUCCESS_WAIT_ELEMENT.getCode())) {
        WebElement webElement = (WebElement) answer.getItem();
        if (webElement != null) {
            if (webElement.getTagName() != null && webElement.getTagName().equalsIgnoreCase("select")) {
                if (webElement.getAttribute("disabled") == null || webElement.getAttribute("disabled").isEmpty()) {
                    Select select = new Select(webElement);
                    result = select.getFirstSelectedOption().getText();
                } else {
                    result = webElement.getText();
                    //result = "Unable to retrieve, element disabled ?";
                }
            } else if (webElement.getTagName() != null && (webElement.getTagName().equalsIgnoreCase("option") || webElement.getTagName().equalsIgnoreCase("input"))) {
                result = webElement.getAttribute("value");
            } else {
                result = webElement.getText();
            }
            /**
             * If return is empty, we search for hidden tags
             */
            if (StringUtil.isNullOrEmpty(result)) {
                String script = "return arguments[0].innerHTML";
                try {
                    result = (String) ((JavascriptExecutor) session.getDriver()).executeScript(script, webElement);
                } catch (Exception e) {
                    LOG.debug("getValueFromHTML locator : '" + identifier.getIdentifier() + "=" + identifier.getLocator() + "', exception : " + e.getMessage());
                }
            }
        }
    } else if (answer.isCodeEquals(MessageEventEnum.ACTION_FAILED_WAIT_NO_SUCH_ELEMENT.getCode())) {
        throw new NoSuchElementException(identifier.getIdentifier() + "=" + identifier.getLocator());
    }
    return result;
}
 
Example 13
Source File: ElementWrapper.java    From opentest with MIT License 4 votes vote down vote up
public ElementWrapper(WebElement element) {
    this.element = element;
    this.text = element.getText();
    this.tag = element.getTagName();
}
 
Example 14
Source File: SmartWebElement.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public String getTagName() {
    WebElement e = getElement();
    return e.getTagName();
}
 
Example 15
Source File: TagValidator.java    From webtester-core with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isValid(WebElement webElement) {
    String elementTagName = webElement.getTagName();
    return tagName.equalsIgnoreCase(elementTagName);
}
 
Example 16
Source File: SelectHelper.java    From hsac-fitnesse-fixtures with Apache License 2.0 4 votes vote down vote up
/**
 * @param element element to check
 * @return true if element is indeed a 'select'.
 */
public static boolean isSelect(WebElement element) {
    String tagName = element.getTagName();
    return "select".equalsIgnoreCase(tagName);
}