List of usage examples for org.openqa.selenium WebElement getTagName
String getTagName();
From source file:org.nuxeo.functionaltests.Locator.java
License:Apache License
/** * Return parent element with given tag name. * <p>//from ww w .ja v a 2s. c o m * Throws a {@link NoSuchElementException} error if no element found. * * @since 7.3 */ public static WebElement findParentTag(WebElement elt, String tagName) { try { By parentBy = By.xpath(".."); WebElement p = elt.findElement(parentBy); while (p != null) { if (tagName.equals(p.getTagName())) { return p; } p = p.findElement(parentBy); } } catch (InvalidSelectorException e) { } throw new NoSuchElementException(String.format("No parent element found with tag %s.", tagName)); }
From source file:org.paxml.selenium.webdriver.PickTagNameTag.java
License:Open Source License
/** * {@inheritDoc}/* ww w.ja v a2s . com*/ */ @Override protected Object onCommand(Context context) { return handleElements(new IElementHandler() { public Object handle(WebElement ele) { return ele.getTagName(); } }); }
From source file:org.paxml.selenium.webdriver.SelectTag.java
License:Open Source License
/** * {@inheritDoc}// w w w . j av a 2 s .co m */ @Override protected Object onCommand(Context context) { for (WebElement ele : findElements(null)) { if (!"select".equalsIgnoreCase(ele.getTagName())) { throw new RuntimeException("Element is not a <select> tag with selector " + getSelector() + ", element is instead: " + ele); } Select dropDown = new Select(ele); if (text != null) { dropDown.selectByVisibleText(text); } else if (index >= 0) { dropDown.selectByIndex(index); } else if (getValue() != null) { dropDown.selectByValue(getValue().toString()); } else { dropDown.deselectAll(); } } return null; }
From source file:org.qe4j.web.OpenWebDriverTest.java
License:Open Source License
@Test public void findElement() throws IOException { Properties properties = getProperties(); WebDriver driver = new OpenWebDriver(properties); driver.get(URL);// w w w .ja va2 s. co m WebElement div = driver.findElement(By.id("html1")); Assert.assertEquals(div.getTagName(), "div", "find element"); }
From source file:org.richfaces.ui.focus.FocusRetriever.java
License:Open Source License
/** * Returns active (focused) element - if no element is focused (it means body element is active), null is returned *///from w ww . j av a2 s .c o m public static WebElement retrieveActiveElement() { GrapheneContext context = GrapheneContext.getContextFor(Default.class); WebElement element = JSInterfaceFactory.create(context, FocusRetriever.class).getActiveElement(); if ("body".equals(element.getTagName())) { return null; } return element; }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testPlotGeneration() { ConsoleTestUtils.resumeConsoleInteraction(driver_); Actions plotCars = new Actions(driver_); plotCars.sendKeys(Keys.ESCAPE + "plot(cars)" + Keys.ENTER); plotCars.perform();// ww w .ja va2s.c o m // Wait for the Plot window to activate final WebElement plotWindow = (new WebDriverWait(driver_, 5)).until(ExpectedConditions .presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.PLOT_IMAGE_FRAME)))); // Wait for a plot to appear in the window Assert.assertEquals(plotWindow.getTagName(), "iframe"); driver_.switchTo().frame(plotWindow); (new WebDriverWait(driver_, 5)).until(ExpectedConditions.presenceOfElementLocated(By.tagName("img"))); // Switch back to document context driver_.switchTo().defaultContent(); }
From source file:org.rstudio.studio.selenium.RConsoleInteraction.java
License:Open Source License
@Test public void testInvokeHelp() { ConsoleTestUtils.resumeConsoleInteraction(driver_); Actions help = new Actions(driver_); help.sendKeys(Keys.ESCAPE + "?lapply" + Keys.ENTER); help.perform();//from ww w. ja va2 s . c o m // Wait for the Help window to activate final WebElement helpWindow = (new WebDriverWait(driver_, 5)).until( ExpectedConditions.presenceOfElementLocated(By.id(ElementIds.getElementId(ElementIds.HELP_FRAME)))); // Wait for help to appear in the window Assert.assertEquals(helpWindow.getTagName(), "iframe"); driver_.switchTo().frame(helpWindow); (new WebDriverWait(driver_, 5)) .until(ExpectedConditions.textToBePresentInElement(By.tagName("body"), "lapply")); // Switch back to document context driver_.switchTo().defaultContent(); }
From source file:org.safs.selenium.util.DocumentClickCapture.java
License:Open Source License
/** * History:/*from ww w . j ava2 s . co m*/ * <pre> * Jun 25, 2015 (LeiWang) Retrieve event's information will spend some time, if the event happens on a remote machine, it will take much longer. * Even if the click really happened and we spend a lot of time on getting the event's information, * the timeout (default 2 seconds) will be reached and the click will be considered not happened, which is not what we want. * To save time, we will not retrieve event's information unless user set {@link #ignoreEventInformation} to false. * <pre> */ private void onEventFired() { String debugmsg = StringUtils.debugmsg(false); setEventFired(true); mouseEvent = new MouseEvent(listenerID); if (!ignoreEventInformation) { String eventHappenTime = ""; try { mouseEvent.EVENT_TYPE = (String) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_TYPE))); } catch (Exception ignore) { } try { mouseEvent.EVENT_PHASE = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_PHASE)))).intValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_TARGET = (WebElement) SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_TARGET)); } catch (Exception ignore) { } try { mouseEvent.EVENT_TIMESTAMP = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_TIMESTAMP)))).longValue(); eventHappenTime = StringUtilities.getTimeString(new Date(mouseEvent.EVENT_TIMESTAMP), true); } catch (Exception ignore) { } //PROBLEM IN FIREFOX 28 WITH SELENIUM 2.41 //try{ mouseEvent.EVENT_VIEW = String.valueOf(SearchObject.executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_VIEW)));}catch(Exception ignore){} try { mouseEvent.EVENT_CURRENTTARGET = (WebElement) SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_CURRENTTARGET)); } catch (Exception ignore) { } try { mouseEvent.EVENT_RELATEDTARGET = (WebElement) SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_RELATEDTARGET)); } catch (Exception ignore) { } try { mouseEvent.EVENT_DETAIL = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_DETAIL)))).longValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_SCREENX = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_SCREENX)))).longValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_SCREENY = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_SCREENY)))).longValue(); } catch (Exception ignore) { } try { WebElement target = mouseEvent.EVENT_TARGET; if (target == null) target = mouseEvent.EVENT_CURRENTTARGET; IndependantLog.debug(debugmsg + " Event '" + mouseEvent.EVENT_TYPE + "' happended at " + eventHappenTime + " on element '" + target.getTagName() + "'" + " at screen location (" + mouseEvent.EVENT_SCREENX + "," + mouseEvent.EVENT_SCREENY + ")."); } catch (Exception ignore) { } try { mouseEvent.EVENT_CLIENTX = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_CLIENTX)))).longValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_CLIENTY = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_CLIENTY)))).longValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_CTRLKEY = ((Boolean) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_CTRLKEY)))).booleanValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_SHIFTKEY = ((Boolean) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_SHIFTKEY)))).booleanValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_ALTKEY = ((Boolean) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_ALTKEY)))).booleanValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_METAKEY = ((Boolean) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_METAKEY)))).booleanValue(); } catch (Exception ignore) { } try { mouseEvent.EVENT_BUTTON = ((Long) (SearchObject .executeScript(JavaScriptFunctions.getGlobalVariable(EVENT_BUTTON)))).intValue(); } catch (Exception ignore) { } } IndependantLog.debug(debugmsg + " setting ready to true."); setReady(true); }
From source file:org.safs.selenium.webdriver.lib.SearchObject.java
License:Open Source License
public static boolean isFrameWebElement(WebElement frameTag) { if (frameTag == null) return false; try {/* w ww .java 2s.c o m*/ String tagName = frameTag.getTagName().toLowerCase(); return TAG_FRAME.equals(tagName) || TAG_IFRAME.equals(tagName); } catch (Exception e) { IndependantLog.warn(StringUtils.debugmsg(false) + "Met " + StringUtils.debugmsg(e)); return false; } }
From source file:org.safs.selenium.webdriver.lib.SearchObject.java
License:Open Source License
/** * According to the type, generate a css selector for the WebElement. * @param type String, the type of the css selector. * @param element WebElement, the WebElement from which a css selector will be generated. * @return String, a css selector.// w w w. j a v a 2s .c o m */ public static String getCssSelector(String type, WebElement element) { StringBuffer cssselector = new StringBuffer(); String tagName = element.getTagName(); if (CSS_SELECTOR_BY_CLASSNAME.equalsIgnoreCase(type)) { String clazz = element.getAttribute(Component.ATTRIBUTE_CLASS); if (clazz != null && !clazz.trim().isEmpty()) { cssselector.append(tagName); cssselector.append("[class='" + clazz + "']"); } } else if (CSS_SELECTOR_BY_ID.equalsIgnoreCase(type)) { String id = element.getAttribute(Component.ATTRIBUTE_ID); if (id != null && !id.trim().isEmpty()) { cssselector.append("[id='" + id + "']"); } } if (cssselector.toString().trim().isEmpty() && !CSS_SELECTOR_BY_ID.equalsIgnoreCase(type)) { String id = element.getAttribute(Component.ATTRIBUTE_ID); if (id != null && !id.trim().isEmpty()) { cssselector.append("[id='" + id + "']"); } } return cssselector.toString(); }