How to use getDomProperty method of org.openqa.selenium.Interface WebElement class

Best Selenium code snippet using org.openqa.selenium.Interface WebElement.getDomProperty

Source:WebDriverWrapper.java Github

copy

Full Screen

...2177 return getFormElement(loc.findElement(getDriver()));2178 }2179 public String getFormElement(WebElement el)2180 {2181 return el.getDomProperty("value");2182 }2183 /**2184 * @deprecated Use {@link org.junit.Assert#assertEquals(String, Object, Object) and {@link #getFormElement(Locator)}}2185 */2186 @Deprecated2187 public void assertFormElementEquals(Locator loc, String value)2188 {2189 assertEquals(value, getFormElement(loc));2190 }2191 /**2192 * @deprecated Use {@link org.junit.Assert#assertEquals(String, Object, Object)} and2193 * {@link #getSelectedOptionText(Locator)}2194 */2195 @Deprecated2196 public void assertOptionEquals(Locator loc, String value)2197 {2198 assertEquals(value, getSelectedOptionText(loc));2199 }2200 public String getSelectedOptionText(Locator loc)2201 {2202 return getSelectedOptionText(loc.findElement(getDriver()));2203 }2204 public String getSelectedOptionText(WebElement el)2205 {2206 Select select = new Select(el);2207 return select.getFirstSelectedOption().getText();2208 }2209 public String getSelectedOptionValue(Locator loc)2210 {2211 return getSelectedOptionValue(loc.findElement(getDriver()));2212 }2213 public String getSelectedOptionValue(WebElement el)2214 {2215 Select select = new Select(el);2216 return select.getFirstSelectedOption().getAttribute("value");2217 }2218 public List<String> getSelectedOptionValues(Locator loc)2219 {2220 Select select = new Select(loc.findElement(getDriver()));2221 List<WebElement> selectedOptions = select.getAllSelectedOptions();2222 List<String> values = new ArrayList<>();2223 for (WebElement selectedOption : selectedOptions)2224 values.add(selectedOption.getAttribute("value"));2225 return values;2226 }2227 public List<String> getSelectOptions(Locator loc)2228 {2229 Select select = new Select(loc.findElement(getDriver()));2230 List<WebElement> selectOptions = select.getOptions();2231 return getTexts(selectOptions);2232 }2233 public void assertElementNotPresent(String errorMsg, Locator loc)2234 {2235 assertFalse(errorMsg, isElementPresent(loc));2236 }2237 public void assertElementNotPresent(Locator loc)2238 {2239 assertElementNotPresent("Element was present in page: " + loc, loc);2240 }2241 public void assertElementNotVisible(Locator loc)2242 {2243 assertFalse("Element was visible in page: " + loc, loc.findElement(getDriver()).isDisplayed());2244 }2245 public void assertElementVisible(Locator loc)2246 {2247 assertTrue("Element was not visible: " + loc, loc.findElement(getDriver()).isDisplayed());2248 }2249 public WebElement scrollIntoView(Locator loc)2250 {2251 return scrollIntoView(loc.findElement(getDriver()));2252 }2253 public WebElement scrollIntoView(Locator loc, Boolean alignToTop)2254 {2255 return scrollIntoView(loc.findElement(getDriver()), alignToTop);2256 }2257 public WebElement scrollIntoView(WebElement el)2258 {2259 return scrollIntoView(el, false);2260 }2261 public WebElement scrollIntoView(WebElement el, Boolean alignToTop)2262 {2263 executeScript("arguments[0].scrollIntoView(arguments[1]);", el, alignToTop);2264 return el;2265 }2266 public void scrollTo(Integer x, Integer y)2267 {2268 executeScript("window.scrollTo(" + x.toString() +", " + y.toString() + ");");2269 }2270 public void scrollToTop()2271 {2272 executeScript("window.scrollTo(0,0);");2273 }2274 public void scrollBy(Integer x, Integer y)2275 {2276 executeScript("window.scrollBy(" + x.toString() +", " + y.toString() + ");");2277 }2278 /**2279 * @deprecated Use {@link WebElement#click()}2280 * find and waitFor methods in Locator now return decorated WebElements that provide special click handling2281 */2282 @Deprecated2283 public void click(WebElement el)2284 {2285 el.click();2286 }2287 public void click(Locator l)2288 {2289 clickAndWait(l, 0);2290 }2291 public void clickAt(Locator l, int xCoord, int yCoord)2292 {2293 clickAt(l, xCoord, yCoord, WAIT_FOR_PAGE);2294 }2295 public void clickAt(Locator l, int xCoord, int yCoord, int pageTimeout)2296 {2297 WebElement el = l.waitForElement(getDriver(), WAIT_FOR_JAVASCRIPT);2298 clickAt(el, xCoord, yCoord, pageTimeout);2299 }2300 public void clickAt(final WebElement el, final int xCoord, final int yCoord, int pageTimeout)2301 {2302 doAndWaitForPageToLoad(() ->2303 {2304 Actions builder = new Actions(getDriver());2305 builder.moveToElement(el, xCoord, yCoord)2306 .click()2307 .build()2308 .perform();2309 }, pageTimeout);2310 }2311 public void clickAndWait(Locator l)2312 {2313 clickAndWait(l, defaultWaitForPage);2314 }2315 public void openLinkInNewWindow(WebElement link)2316 {2317 Keys modifierKey = SystemUtils.IS_OS_MAC ? Keys.COMMAND : Keys.CONTROL;2318 link.sendKeys(Keys.chord(modifierKey, Keys.ENTER));2319 switchToWindow(1);2320 waitForDocument();2321 }2322 public static final int WAIT_FOR_EXT_MASK_TO_DISSAPEAR = -1;2323 public static final int WAIT_FOR_EXT_MASK_TO_APPEAR = -2;2324 public void clickAndWait(Locator l, int pageTimeoutMs)2325 {2326 WebElement el;2327 try2328 {2329 el = l.findElement(getDriver());2330 clickAndWait(el, pageTimeoutMs);2331 }2332 catch (StaleElementReferenceException e)2333 {2334 // Locator.findElement likely didn't return the element we wanted due to timing problem. Wait and try again.2335 // Ideally we'd decorate WebElement to know its locator and encapsulate the retry.2336 sleep(500);2337 el = l.findElement(getDriver());2338 clickAndWait(el, pageTimeoutMs);2339 log("WARNING: Need to improve timing, clicked element immediately became stale.: " + el.toString());2340 }2341 }2342 public void clickAndWait(WebElement el)2343 {2344 clickAndWait(el, getDefaultWaitForPage());2345 }2346 public void clickAndWait(final WebElement el, int pageTimeoutMs)2347 {2348 doAndWaitForPageToLoad(() ->2349 {2350 el.click();2351 }, pageTimeoutMs);2352 if(pageTimeoutMs==WAIT_FOR_EXT_MASK_TO_APPEAR)2353 _extHelper.waitForExt3Mask(WAIT_FOR_JAVASCRIPT);2354 else if(pageTimeoutMs==WAIT_FOR_EXT_MASK_TO_DISSAPEAR)2355 _extHelper.waitForExt3MaskToDisappear(WAIT_FOR_JAVASCRIPT);2356 }2357 public void doubleClick(Locator l)2358 {2359 doubleClickAndWait(l, 0);2360 }2361 public void doubleClickAndWait(final Locator l, int millis)2362 {2363 doubleClickAndWait(l.findElement(getDriver()), millis);2364 }2365 public void doubleClick(WebElement l)2366 {2367 doubleClickAndWait(l, 0);2368 }2369 public void doubleClickAndWait(final WebElement l, int millis)2370 {2371 doAndWaitForPageToLoad(() ->2372 {2373 Actions action = new Actions(getDriver());2374 action.doubleClick(l).perform();2375 }, millis);2376 }2377 public void selectFolderTreeItem(String folderName)2378 {2379 click(Locator.permissionsTreeNode(folderName));2380 }2381 /**2382 * Move mouse to the upper left corner of the document to dismiss tooltips and the like2383 * Will scroll page if necessary2384 */2385 public void mouseOut()2386 {2387 try2388 {2389 scrollTo(0, 0);2390 WebElement root = Locators.documentRoot.findElement(getDriver());2391 final Dimension rootSize = root.getSize();2392 new Actions(getDriver()).moveToElement(root, - (rootSize.getWidth() / 2), - (rootSize.getHeight() / 2)).perform();2393 }2394 catch (WebDriverException ignore) { }2395 }2396 public void mouseOver(Locator l)2397 {2398 WebElement el = l.findElement(getDriver());2399 mouseOver(el);2400 }2401 public void mouseOver(WebElement el)2402 {2403 scrollIntoView(el);2404 Actions builder = new Actions(getDriver());2405 builder.moveToElement(el)2406 // Add a little wiggle to make sure tooltips notice2407 .moveByOffset(2, 0)2408 .moveByOffset(-4, 0)2409 .moveByOffset(2, 0)2410 .perform();2411 }2412 public int getElementIndex(Locator.XPathLocator l)2413 {2414 return l.child("preceding-sibling::*").findElements(getDriver()).size();2415 }2416 public int getElementIndex(WebElement el)2417 {2418 return Locator.xpath("preceding-sibling::*").findElements(el).size();2419 }2420 public void dragAndDrop(Locator from, Locator to)2421 {2422 dragAndDrop(from, to, Position.top);2423 }2424 public void dragAndDrop(WebElement from, WebElement to)2425 {2426 dragAndDrop(from, to, Position.top);2427 }2428 public enum Position2429 {top, bottom, middle}2430 public void dragAndDrop(Locator from, Locator to, Position pos)2431 {2432 WebElement fromEl = from.findElement(getDriver());2433 WebElement toEl = to.findElement(getDriver());2434 dragAndDrop(fromEl, toEl, pos);2435 }2436 public void dragAndDrop(WebElement fromEl, WebElement toEl, Position pos)2437 {2438 int y;2439 switch (pos)2440 {2441 case top:2442 y = 1;2443 break;2444 case bottom:2445 y = toEl.getSize().getHeight() - 1;2446 break;2447 case middle:2448 y = toEl.getSize().getHeight() / 2;2449 break;2450 default:2451 throw new IllegalArgumentException("Unexpected position: " + pos.toString());2452 }2453 Actions builder = new Actions(getDriver());2454 builder.clickAndHold(fromEl).moveToElement(toEl, toEl.getSize().getWidth() / 2, y).release().build().perform();2455 }2456 public void dragAndDrop(Locator el, int xOffset, int yOffset)2457 {2458 WebElement fromEl = el.findElement(getDriver());2459 dragAndDrop(fromEl, xOffset, yOffset);2460 }2461 public void dragAndDrop(WebElement fromEl, int xOffset, int yOffset)2462 {2463 Actions builder = new Actions(getDriver());2464 builder.clickAndHold(fromEl).moveByOffset(xOffset + 1, yOffset + 1).release().build().perform();2465 }2466 // This is useful when making a draggin selection in a plot, and there may be many elements ontop of the one you want.2467 public void dragAndDrop(int xOffset, int yOffset)2468 {2469 Actions builder = new Actions(getDriver());2470 builder.clickAndHold().moveByOffset(xOffset + 1, yOffset + 1).release().build().perform();2471 }2472 /**2473 * @deprecated Use {@link #getTableCellText(org.labkey.test.Locator.XPathLocator, int, int)}2474 */2475 @Deprecated2476 private String getTableCellText(String tableId, int row, int column)2477 {2478 return getTableCellText(Locator.xpath("//table[@id=" + Locator.xq(tableId) + "]"), row, column);2479 }2480 public String getTableCellText(Locator.XPathLocator table, int row, int column)2481 {2482 return getText(getSimpleTableCell(table, row, column));2483 }2484 public Locator getSimpleTableCell(Locator.XPathLocator table, int row, int column)2485 {2486 return table.append("/tbody/tr[" + (row + 1) + "]/*[self::td or self::th][" + (column + 1) + "]");2487 }2488 /**2489 * @deprecated Use {@link #getTableCellText(org.labkey.test.Locator.XPathLocator, int, int)} and {@link org.junit.Assert#assertEquals(Object, Object)}2490 */2491 @Deprecated public void assertTableCellTextEquals(String tableName, int row, int column, String value)2492 {2493 assertEquals(tableName + "." + String.valueOf(row) + "." + String.valueOf(column) + " != \"" + value + "\"", value, getTableCellText(tableName, row, column));2494 }2495 /**2496 * @deprecated Use {@link #getTableCellText(org.labkey.test.Locator.XPathLocator, int, int)} and {@link #assertElementContains(Locator, String)}2497 */2498 @Deprecated public void assertTableCellContains(String tableName, int row, int column, String... strs)2499 {2500 String cellText = getTableCellText(tableName, row, column);2501 for (String str : strs)2502 {2503 assertTrue(tableName + "." + row + "." + column + " should contain \'" + str + "\' (actual value is " + cellText + ")", cellText.contains(str));2504 }2505 }2506 /**2507 * @deprecated Use {@link #getTableCellText(org.labkey.test.Locator.XPathLocator, int, int)}2508 */2509 @Deprecated public void assertTableCellNotContains(String tableName, int row, int column, String... strs)2510 {2511 String cellText = getTableCellText(tableName, row, column);2512 for (String str : strs)2513 {2514 assertFalse(tableName + "." + row + "." + column + " should not contain \'" + str + "\'", cellText.contains(str));2515 }2516 }2517 // Specifies cell values in a TSV string -- values are separated by tabs, rows are separated by \n2518 public void assertTableRowsEqual(String tableId, int startRow, String cellValuesTsv)2519 {2520 String[] lines = cellValuesTsv.split("\n");2521 String[][] cellValues = new String[lines.length][];2522 for (int row = 0; row < cellValues.length; row++)2523 cellValues[row] = lines[row].split("\t");2524 assertTableRowsEqual(tableId, startRow, cellValues);2525 }2526 public void assertTableRowsEqual(String tableId, int startRow, String[][] cellValues)2527 {2528 for (int row = 0; row < cellValues.length; row++)2529 for (int col = 0; col < cellValues[row].length; col++)2530 assertTableCellTextEquals(tableId, row + startRow, col, cellValues[row][col]);2531 }2532 /**2533 * @deprecated Use {@link org.labkey.test.util.DataRegionTable#getColumnDataAsText(int)}2534 */2535 @Deprecated2536 // Returns the value of all cells in the specified column2537 public List<String> getTableColumnValues(String tableName, int column)2538 {2539 int rowCount = getTableRowCount(tableName);2540 List<String> values = new ArrayList<>(rowCount);2541 for (int i = 0; i < rowCount; i++)2542 {2543 try2544 {2545 values.add(getTableCellText(Locator.id(tableName), i, column));2546 }2547 catch(NoSuchElementException ignore) {}2548 }2549 return values;2550 }2551 // Returns the number of rows (both <tr> and <th>) in the specified table2552 public int getTableRowCount(String tableName)2553 {2554 return Locator.xpath("//table[@id=" + Locator.xq(tableName) + "]/thead/tr").findElements(getDriver()).size() +2555 Locator.xpath("//table[@id=" + Locator.xq(tableName) + "]/tbody/tr").findElements(getDriver()).size();2556 }2557 /**2558 * @deprecated Slow to return false. Use a specific Locator2559 */2560 @Deprecated2561 public boolean isButtonPresent(String text)2562 {2563 try2564 {2565 findButton(text);2566 return true;2567 }2568 catch (NoSuchElementException notPresent)2569 {2570 return false;2571 }2572 }2573 public void clickButtonByIndex(String text, int index)2574 {2575 clickButtonByIndex(text, index, defaultWaitForPage);2576 }2577 public void clickButtonByIndex(String text, int index, int wait)2578 {2579 clickAndWait(findButton(text, index), wait);2580 }2581 public WebElement findButton(String text, int index)2582 {2583 Locator.XPathLocator locators = Locator.XPathLocator.union(2584 // check for normal labkey button:2585 Locator.lkButton(text).index(index),2586 // check for Ext 4 button:2587 Ext4Helper.Locators.ext4Button(text).index(index),2588 // check for Ext button:2589 Locator.extButton(text).index(index),2590 // check for normal html button:2591 Locator.button(text).index(index),2592 // check for bootstrap button2593 BootstrapLocators.button(text).index(index)2594 );2595 try2596 {2597 return waitForElement(locators);2598 }2599 catch (NoSuchElementException notFound)2600 {2601 throw new NoSuchElementException("No button found with text \"" + text + "\" at index " + index, notFound);2602 }2603 }2604 public WebElement findButton(String text)2605 {2606 Locator.XPathLocator locators = Locator.XPathLocator.union(2607 // normal labkey nav button:2608 Locator.lkButton(text),2609 // Ext 4 button:2610 Ext4Helper.Locators.ext4Button(text),2611 // Ext 3 button:2612 Locator.extButton(text),2613 // normal HTML button:2614 Locator.button(text),2615 // GWT button:2616 Locator.gwtButton(text),2617 // bootstrap button2618 BootstrapLocators.button(text)2619 );2620 try2621 {2622 return waitForElement(locators);2623 }2624 catch (NoSuchElementException tryCaps)2625 {2626 if (!text.equals(text.toUpperCase()))2627 {2628 log("WARNING: Update test. Possible wrong casing for button: " + text);2629 try2630 {2631 return findButton(text.toUpperCase());2632 }2633 catch (NoSuchElementException capsFailed) {}2634 }2635 throw new NoSuchElementException("No button found with text " + text, tryCaps);2636 }2637 }2638 protected WebElement findButtonContainingText(String text)2639 {2640 Locator.XPathLocator locators = Locator.XPathLocator.union(2641 // normal labkey button:2642 Locator.lkButton().containing(text),2643 // Ext 4 button:2644 Ext4Helper.Locators.ext4ButtonContainingText(text),2645 // Ext 3 button:2646 Locator.extButtonContainingText(text),2647 // normal HTML button:2648 Locator.buttonContainingText(text),2649 // check for bootstrap button2650 BootstrapLocators.button().containing(text)2651 );2652 try2653 {2654 return waitForElement(locators);2655 }2656 catch (NoSuchElementException notFound)2657 {2658 throw new NoSuchElementException("No button found containing text " + text, notFound);2659 }2660 }2661 /**2662 * Wait for a button to appear, click it, then waits for the page to load.2663 * Use clickButton(text, 0) to click a button and continue immediately.2664 */2665 public void clickButton(String text)2666 {2667 clickButton(text, defaultWaitForPage);2668 }2669 /**2670 * Wait for a button to appear, click it, then waits for the text to appear.2671 * @deprecated This method provides minimal convenience and behaves inconsistently with other 'clickButton' methods2672 */2673 @Deprecated(since = "21.8")2674 public void clickButton(String text, String waitForText)2675 {2676 if (isTextPresent(waitForText))2677 {2678 throw new IllegalStateException("'" + waitForText + "' is already present on the page. Pick a better indicator that the page state has changed.");2679 }2680 clickButton(text, 0);2681 waitForText(waitForText);2682 }2683 /**2684 * Wait for a button to appear, click it, then wait for <code>waitMillis</code> for the page to load.2685 */2686 public void clickButton(final String text, int waitMillis)2687 {2688 clickButton(text, waitMillis, 0);2689 }2690 /**2691 * Wait for a button to appear, click it, then wait for <code>waitMillis</code> for the page to load.2692 * -- which is which button of this name (first, second, etc.)2693 */2694 public void clickButton(final String text, int waitMillis, int which)2695 {2696 clickAndWait(findButton(text, which), waitMillis);2697 }2698 /**2699 * @deprecated Avoid me please. I am bad and hacky2700 * Mash button until it goes stale and page loads2701 */2702 @Deprecated2703 public void mashButton(final String text)2704 {2705 WebElement button = findButton(text);2706 scrollIntoView(button);2707 doAndWaitForPageToLoad(() -> shortWait().until(LabKeyExpectedConditions.clickUntilStale(button)));2708 }2709 public void clickButtonContainingText(String text)2710 {2711 clickButtonContainingText(text, defaultWaitForPage);2712 }2713 public void clickButtonContainingText(String text, int waitMills)2714 {2715 clickAndWait(findButtonContainingText(text), waitMills);2716 }2717 public void clickButtonContainingText(String buttonText, String textShouldAppearAfterLoading)2718 {2719 clickButtonContainingText(buttonText, 0);2720 waitForText(defaultWaitForPage, textShouldAppearAfterLoading);2721 }2722 /**2723 * wait for element, click it, return immediately2724 */2725 public void waitAndClick(Locator l)2726 {2727 waitAndClick(WAIT_FOR_JAVASCRIPT, l, 0);2728 }2729 /**2730 * wait for element, click it, wait for page to load2731 */2732 public void waitAndClickAndWait(Locator l)2733 {2734 waitAndClick(WAIT_FOR_JAVASCRIPT, l, WAIT_FOR_PAGE);2735 }2736 /**2737 * wait for element, click it, wait for page to load2738 */2739 public void waitAndClick(int waitFor, Locator l, int waitForPageToLoad)2740 {2741 WebElement el = l.waitForElement(getDriver(), waitFor);2742 try2743 {2744 clickAndWait(el, waitForPageToLoad);2745 }2746 catch (StaleElementReferenceException e)2747 {2748 // Locator.findElement likely didn't return the element we wanted due to timing problem. Wait and try again.2749 // Ideally we'd decorate WebElement to know its locator and encapsulate the retry.2750 sleep(500);2751 el = l.findElement(getDriver());2752 clickAndWait(el, waitForPageToLoad);2753 }2754 }2755 /** @return target of link */2756 public String getLinkHref(String linkText, String controller, String folderPath)2757 {2758 Locator link = Locator.linkWithText(linkText);2759 String localAddress = getButtonHref(link, true);2760 // IE puts the entire link in href, not just the local address2761 if (localAddress.contains("/"))2762 {2763 int location = localAddress.lastIndexOf("/");2764 if (location < localAddress.length() - 1)2765 localAddress = localAddress.substring(location + 1);2766 }2767 return (WebTestHelper.getContextPath() + "/" + controller + folderPath + "/" + localAddress);2768 }2769 public String getButtonHref(Locator buttonLoc, boolean truncate)2770 {2771 String address = getAttribute(buttonLoc, "href");2772 // IE puts the entire link in href, not just the local address2773 if (truncate && address.contains("/"))2774 {2775 int location = address.lastIndexOf("/");2776 if (location < address.length() - 1)2777 address = address.substring(location + 1);2778 }2779 return address;2780 }2781 public void setFormElement(Locator l, String text)2782 {2783 WebElement el = l.waitForElement(new WebDriverWait(getDriver(), Duration.ofMillis(WAIT_FOR_JAVASCRIPT)));2784 setFormElement(el, text);2785 }2786 /**2787 * Clears and sets the text of the specified input element.2788 * Warning: Clear unfocuses the element which causes some inputs to disappear.2789 * See <a href="https://www.w3.org/TR/webdriver/#element-clear">WebDriver Docs</a>2790 * Use {@link WebElement#sendKeys} for such inputs.2791 */2792 public void setFormElement(WebElement el, String text)2793 {2794 String inputType = el.getAttribute("type");2795 if ("file".equals(inputType))2796 {2797 log("WARNING: Please use File object to set file input");2798 setFormElement(el, new File(text));2799 return;2800 }2801 if (isHtml5InputTypeSupported(inputType))2802 {2803 setHtml5Input(el, inputType, text);2804 }2805 else2806 {2807 setInput(el, text);2808 }2809 }2810 private void setInput(WebElement input, String text)2811 {2812 if (StringUtils.isEmpty(text))2813 {2814 input.clear();2815 }2816 else if (!input.getTagName().equals("select") && text.length() < 1000 && !text.contains("\n") && !text.contains("\t"))2817 {2818 input.clear();2819 if (!waitFor(()-> input.getDomProperty("value").length() == 0, 500))2820 {2821 TestLogger.warn("Failed to clear input: " + input);2822 }2823 input.sendKeys(text);2824 if (!waitFor(()-> input.getDomProperty("value").equals(text), 500))2825 {2826 TestLogger.warn("Failed to set input: " + input);2827 }2828 }2829 else2830 {2831 setFormElementJS(input, text);2832 }2833 try2834 {2835 String elementClass = input.getAttribute("class");2836 if (elementClass.contains("gwt-TextBox") || elementClass.contains("gwt-TextArea") || elementClass.contains("x-form-text"))2837 fireEvent(input, SeleniumEvent.blur); // Make GWT and ExtJS form elements behave better2838 }...

Full Screen

Full Screen

Source:WebElement.java Github

copy

Full Screen

...94 *95 * @param name The name of the property.96 * @return The property's current value or null if the value is not set.97 */98 default String getDomProperty(String name) {99 throw new UnsupportedOperationException();100 }101 /**102 * Get the value of the given attribute of the element.103 * <p>104 * This method, unlike {@link #getAttribute(String)}, returns the value of the attribute with the105 * given name but not the property with the same name.106 * <p>107 * The following are deemed to be "boolean" attributes, and will return either "true" or null:108 * <p>109 * async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,110 * defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,111 * iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade,112 * novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless,113 * seeking, selected, truespeed, willvalidate114 * <p>115 * See <a href="https://w3c.github.io/webdriver/#get-element-attribute">W3C WebDriver specification</a>116 * for more details.117 *118 * @param name The name of the attribute.119 * @return The attribute's value or null if the value is not set.120 */121 default String getDomAttribute(String name) {122 throw new UnsupportedOperationException();123 }124 /**125 * Get the value of the given attribute of the element. Will return the current value, even if126 * this has been modified after the page has been loaded.127 * <p>128 * More exactly, this method will return the value of the property with the given name, if it129 * exists. If it does not, then the value of the attribute with the given name is returned. If130 * neither exists, null is returned.131 * <p>132 * The "style" attribute is converted as best can be to a text representation with a trailing133 * semi-colon.134 * <p>135 * The following are deemed to be "boolean" attributes, and will return either "true" or null:136 * <p>137 * async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked,138 * defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate,139 * iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade,140 * novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless,141 * seeking, selected, truespeed, willvalidate142 * <p>143 * Finally, the following commonly mis-capitalized attribute/property names are evaluated as144 * expected:145 * <ul>146 * <li>If the given name is "class", the "className" property is returned.147 * <li>If the given name is "readonly", the "readOnly" property is returned.148 * </ul>149 * <i>Note:</i> The reason for this behavior is that users frequently confuse attributes and150 * properties. If you need to do something more precise, use {@link #getDomAttribute(String)}151 * or {@link #getDomProperty(String)} to obtain the result you desire.152 * <p>153 * See <a href="https://w3c.github.io/webdriver/#get-element-attribute">W3C WebDriver specification</a>154 * for more details.155 *156 * @param name The name of the attribute.157 * @return The attribute/property's current value or null if the value is not set.158 */159 String getAttribute(String name);160 /**161 * Gets result of computing the WAI-ARIA role of element.162 * <p>163 * See <a href="https://www.w3.org/TR/webdriver/#get-computed-role">W3C WebDriver specification</a>164 * for more details.165 *...

Full Screen

Full Screen

Source:GrapheneElementImpl.java Github

copy

Full Screen

...255 public String getDomAttribute(String name) {256 return element.getDomAttribute(name);257 }258 @Override259 public String getDomProperty(String name) {260 return element.getDomProperty(name);261 }262 @Override263 public SearchContext getShadowRoot() {264 return element.getShadowRoot();265 }266 @Override267 public int hashCode() {268 if (element == null) {269 // shouldn't ever happen270 return super.hashCode();271 }272 // see #equals for explanation273 return element.hashCode();274 }...

Full Screen

Full Screen

getDomProperty

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.support.ui.Select;6public class Test {7 public static void main(String[] args) {8 System.setProperty("webdriver.chrome.driver", "C:\\Users\\sudhakar\\Downloads\\chromedriver_win32\\chromedriver.exe");9 WebDriver driver=new ChromeDriver();10 WebElement country=driver.findElement(By.name("country"));11 Select sel=new Select(country);12 sel.selectByVisibleText("ANTARCTICA");13 String value=element.getAttribute("value");14 System.out.println("Value of the attribute is :"+value);15 String text=element.getText();16 System.out.println("Text of the attribute is :"+text);17 String tagName=element.getTagName();18 System.out.println("Tag name is :"+tagName);19 String cssValue=element.getCssValue("color");20 System.out.println("CSS value is :"+cssValue);21 String domValue=element.getAttribute("value");22 System.out.println("DOM value is :"+domValue);23 }24}25CSS value is :rgba(0, 0, 0, 1)26public String getDomProperty(String name)27import org.openqa.selenium.By;28import org.openqa.selenium.WebDriver;29import org.openqa.selenium.WebElement;30import org.openqa.selenium.chrome.ChromeDriver;31import org.openqa.selenium.support.ui.Select;32public class Test {33 public static void main(String[] args) {

Full Screen

Full Screen

getDomProperty

Using AI Code Generation

copy

Full Screen

1String value = element.getAttribute("value");2String value = element.getAttribute("value");3String value = element.getAttribute("value");4String value = element.getAttribute("value");5String value = element.getAttribute("value");6String value = element.getAttribute("value");7String value = element.getAttribute("value");8String value = element.getAttribute("value");9String value = element.getAttribute("value");10String value = element.getAttribute("value");11String value = element.getAttribute("value");12String value = element.getAttribute("value");13String value = element.getAttribute("value");

Full Screen

Full Screen

getDomProperty

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.By;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.chrome.ChromeDriver;5public class GetDomProperty {6 public static void main(String[] args) {7 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Saurabh\\Downloads\\chromedriver_win32\\chromedriver.exe");8 WebDriver driver = new ChromeDriver();9 WebElement searchBox = driver.findElement(By.name("q"));10 String searchBoxValue = searchBox.getAttribute("value");11 System.out.println(searchBoxValue);12 driver.close();13 }14}15### 2.2.2. getCssValue()16> getCssValue(propertyName)

Full Screen

Full Screen

getDomProperty

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(By.id("myName"));2String value = element.getAttribute("name");3WebElement element = driver.findElement(By.id("myName"));4String value = element.getAttribute("name");5WebElement element = driver.findElement(By.id("myName"));6String value = element.getAttribute("name");7WebElement element = driver.findElement(By.id("myName"));8String value = element.getAttribute("name");9WebElement element = driver.findElement(By.id("myName"));10String value = element.getAttribute("name");11WebElement element = driver.findElement(By.id("myName"));12String value = element.getAttribute("name");13WebElement element = driver.findElement(By.id("myName"));14String value = element.getAttribute("name");15WebElement element = driver.findElement(By.id("myName"));16String value = element.getAttribute("name");17WebElement element = driver.findElement(By.id("myName"));18String value = element.getAttribute("name");

Full Screen

Full Screen

getDomProperty

Using AI Code Generation

copy

Full Screen

1WebElement element = driver.findElement(By.id("id"));2String value = element.getDomProperty("id");3String getAttribute(String attributeName)4WebElement element = driver.findElement(By.id("id"));5String value = element.getAttribute("id");6String getCssValue(String propertyName)7WebElement element = driver.findElement(By.id("id"));8String value = element.getCssValue("id");9String getProperty(String propertyName)10WebElement element = driver.findElement(By.id("id"));11String value = element.getProperty("id");12String getTagName()13WebElement element = driver.findElement(By.id("id"));14String value = element.getTagName();15String getText()16WebElement element = driver.findElement(By.id("id"));17String value = element.getText();

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful