How to use getWrappedElement method of org.fluentlenium.core.domain.ElementUtils class

Best FluentLenium code snippet using org.fluentlenium.core.domain.ElementUtils.getWrappedElement

Source:FluentDriver.java Github

copy

Full Screen

...31import org.slf4j.Logger;32import org.slf4j.LoggerFactory;33import java.util.Date;34import java.util.Set;35import static org.fluentlenium.core.domain.ElementUtils.getWrappedElement;36import static org.fluentlenium.utils.Preconditions.checkArgument;37import static org.fluentlenium.utils.Preconditions.checkState;38/**39 * Wrapper class for a {@link WebDriver} instance which also offers shortcut and convenience methods,40 * as well as methods to work with mouse, keyboard and windows.41 */42@SuppressWarnings("PMD.GodClass")43public class FluentDriver extends AbstractFluentDriverSearchControl { // NOPMD GodClass44 private static final Logger LOGGER =45 LoggerFactory.getLogger(FluentDriver.class);46 private final Configuration configuration;47 private final ComponentsManager componentsManager;48 private final EventsRegistry events;49 private final ComponentsEventsRegistry componentsEventsRegistry;50 private final FluentInjector fluentInjector;51 private final CssControl cssControl; // NOPMD UnusedPrivateField52 private final Search search;53 private final WebDriver driver;54 private final MouseActions mouseActions;55 private final KeyboardActions keyboardActions;56 private final WindowAction windowAction;57 private final FluentDriverScreenshotPersister screenshotPersister;58 private final FluentDriverWrappedCapabilitiesProvider capabilitiesProvider;59 private final FluentDriverHtmlDumper htmlDumper;60 private final FluentDriverWait driverWait;61 private final PerformanceTiming performanceTiming;62 private final ChromiumControl chromiumControl;63 /**64 * Wrap the driver into a Fluent driver.65 *66 * @param driver underlying selenium driver67 * @param configuration configuration68 * @param adapter adapter fluent control interface69 */70 public FluentDriver(WebDriver driver, Configuration configuration, FluentControl adapter) {71 super(adapter);72 this.configuration = configuration;73 screenshotPersister = new FluentDriverScreenshotPersister(configuration, driver);74 capabilitiesProvider = new FluentDriverWrappedCapabilitiesProvider();75 htmlDumper = new FluentDriverHtmlDumper(configuration);76 componentsManager = new ComponentsManager(adapter);77 driverWait = new FluentDriverWait(configuration);78 this.driver = driver;79 search = new Search(driver, this, componentsManager, adapter);80 if (driver instanceof EventFiringWebDriver) {81 events = new EventsRegistry(this);82 componentsEventsRegistry = new ComponentsEventsRegistry(events, componentsManager);83 } else {84 events = null;85 componentsEventsRegistry = null;86 }87 mouseActions = new MouseActions(driver);88 keyboardActions = new KeyboardActions(driver);89 fluentInjector = new FluentInjector(adapter, events, componentsManager, new DefaultContainerInstantiator(this));90 cssControl = new CssControlImpl(adapter, adapter);91 windowAction = new WindowAction(adapter, componentsManager.getInstantiator(), driver);92 performanceTiming = new DefaultPerformanceTiming(driver);93 chromiumControl = new ChromiumControlImpl(driver);94 new FluentDriverTimeoutConfigurer(configuration, driver).configureDriver();95 }96 public Configuration getConfiguration() {97 return configuration;98 }99 @Override100 public void takeHtmlDump() {101 takeHtmlDump(new Date().getTime() + ".html");102 }103 @Override104 public void takeHtmlDump(String fileName) {105 htmlDumper.takeHtmlDump(fileName, () -> {106 synchronized (FluentDriver.class) {107 return $("html").first().html();108 }109 });110 }111 @Override112 public boolean canTakeScreenShot() {113 return getDriver() instanceof TakesScreenshot;114 }115 @Override116 public void takeScreenshot() {117 takeScreenshot(new Date().getTime() + ".png");118 }119 @Override120 public void takeScreenshot(String fileName) {121 if (!canTakeScreenShot()) {122 throw new WebDriverException("Current browser doesn't allow taking screenshot.");123 }124 screenshotPersister.persistScreenshot(fileName);125 }126 @Override127 public WebDriver getDriver() {128 if (driver instanceof AppiumDriver) {129 LOGGER.warn("You should use getAppiumDriver() method for mobile automation");130 }131 return driver;132 }133 @Override134 public AppiumDriver getAppiumDriver() {135 if (!(driver instanceof AppiumDriver)) {136 throw new WrongDriverException("Use getDriver() method for web automation");137 }138 return (AppiumDriver) driver;139 }140 @Override141 public EventsRegistry events() {142 return checkState(events, "An EventFiringWebDriver instance is required to use events. "143 + "You should set 'eventsEnabled' configuration property to 'true' "144 + "or override newWebDriver() to build an EventFiringWebDriver.");145 }146 @Override147 public MouseActions mouse() {148 return mouseActions;149 }150 @Override151 public KeyboardActions keyboard() {152 return keyboardActions;153 }154 @Override155 public WindowAction window() {156 return windowAction;157 }158 @Override159 public FluentWait await() {160 return driverWait.await(this);161 }162 @Override163 public Set<Cookie> getCookies() {164 return getDriver().manage().getCookies();165 }166 @Override167 public Cookie getCookie(String name) {168 return getDriver().manage().getCookieNamed(name);169 }170 @Override171 public String url() {172 String baseUrl = buildUrl(null);173 String currentUrl = getDriver().getCurrentUrl();174 if (currentUrl != null && baseUrl != null && currentUrl.startsWith(baseUrl)) {175 currentUrl = currentUrl.substring(baseUrl.length());176 }177 return currentUrl;178 }179 private String buildUrl(String url) {180 String currentUrl = getDriver().getCurrentUrl();181 String baseUrl = UrlUtils.sanitizeBaseUrl(getBaseUrl(), currentUrl);182 return UrlUtils.concat(baseUrl, url);183 }184 @Override185 public String pageSource() {186 return getDriver().getPageSource();187 }188 @Override189 public <P extends FluentPage> P goTo(P page) {190 checkArgument(page, "It is required to specify an instance of FluentPage for navigation.");191 page.go();192 return page;193 }194 @Override195 public void goTo(String url) {196 checkArgument(url, "It is required to specify a URL to navigate to.");197 getDriver().get(buildUrl(url));198 }199 @Override200 public void goToInNewTab(String url) {201 checkArgument(url, "It is required to specify a URL to navigate to (in a new tab).");202 String newTab;203 synchronized (getClass()) {204 Set<String> initialTabs = getDriver().getWindowHandles();205 executeScript("window.open('" + buildUrl(url) + "', '_blank');");206 Set<String> tabs = getDriver().getWindowHandles();207 tabs.removeAll(initialTabs);208 newTab = tabs.iterator().next();209 }210 getDriver().switchTo().window(newTab);211 }212 @Override213 public Capabilities capabilities() {214 return capabilitiesProvider.getCapabilities(getDriver());215 }216 @Override217 public FluentJavascript executeScript(String script, Object... args) {218 return new FluentJavascript((JavascriptExecutor) getDriver(), false, script, args);219 }220 @Override221 public FluentJavascript executeAsyncScript(String script, Object... args) {222 return new FluentJavascript((JavascriptExecutor) getDriver(), true, script, args);223 }224 @Override225 public void switchTo(FluentList<? extends FluentWebElement> elements) {226 switchTo(elements.first());227 }228 @Override229 public void switchTo(FluentWebElement element) {230 if (null == element || !"iframe".equals(element.tagName())) {231 getDriver().switchTo().defaultContent();232 } else {233 WebElement target = element.getElement();234 while (target instanceof WrapsElement && target != getWrappedElement(target)) {235 target = getWrappedElement(target);236 }237 getDriver().switchTo().frame(target);238 }239 }240 @Override241 public void switchTo() {242 switchTo((FluentWebElement) null);243 }244 @Override245 public void switchToDefault() {246 switchTo((FluentWebElement) null);247 }248 @Override249 public Alert alert() {...

Full Screen

Full Screen

Source:ComponentsManager.java Github

copy

Full Screen

1package org.fluentlenium.core.components;2import static org.fluentlenium.core.domain.ElementUtils.getWrappedElement;3import org.fluentlenium.core.FluentControl;4import org.fluentlenium.core.proxy.LocatorProxies;5import org.fluentlenium.core.proxy.ProxyElementListener;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.WrapsElement;8import org.openqa.selenium.support.pagefactory.ElementLocator;9import java.util.ArrayList;10import java.util.HashSet;11import java.util.IdentityHashMap;12import java.util.List;13import java.util.Map;14import java.util.Set;15/**16 * Manage living components for a WebDriver instance.17 * <p>18 * A component is an Object implementing no particular interface, but capable of wrapping19 * a {@link org.openqa.selenium.WebElement}.20 * <p>21 * {@link org.fluentlenium.core.domain.FluentWebElement} is the most common component.22 */23public class ComponentsManager extends AbstractComponentInstantiator24 implements ComponentInstantiator, ComponentsAccessor, ProxyElementListener {25 private final DefaultComponentInstantiator instantiator;26 private final Map<WebElement, Set<Object>> components = new IdentityHashMap<>();27 private final List<ComponentsListener> listeners = new ArrayList<>();28 /**29 * Creates a new components manager.30 *31 * @param control control interface32 */33 public ComponentsManager(FluentControl control) {34 instantiator = new DefaultComponentInstantiator(control, this);35 }36 /**37 * Get the component instantiator used by this components manager.38 *39 * @return component instantiator40 */41 public ComponentInstantiator getInstantiator() {42 return instantiator;43 }44 @Override45 public Set<Object> getComponents(WebElement element) {46 return components.get(unwrapElement(element));47 }48 @Override49 public boolean isComponentClass(Class<?> componentClass) {50 return instantiator.isComponentClass(componentClass);51 }52 @Override53 public boolean isComponentListClass(Class<? extends List<?>> componentListClass) {54 return instantiator.isComponentListClass(componentListClass);55 }56 @Override57 public <T> T newComponent(Class<T> componentClass, WebElement element) {58 T component = instantiator.newComponent(componentClass, element);59 register(element, component);60 return component;61 }62 @Override63 public boolean addComponentsListener(ComponentsListener listener) {64 synchronized (this) {65 return listeners.add(listener);66 }67 }68 @Override69 public boolean removeComponentsListener(ComponentsListener listener) {70 synchronized (this) {71 return listeners.remove(listener);72 }73 }74 /**75 * Fire component registered event.76 *77 * @param element underlying element78 * @param component registered component79 */80 protected void fireComponentRegistered(WebElement element, Object component) {81 synchronized (this) {82 for (ComponentsListener listener : listeners) {83 listener.componentRegistered(element, component);84 }85 }86 }87 /**88 * Fire component released event.89 *90 * @param element underlying element91 * @param component released component92 */93 protected void fireComponentReleased(WebElement element, Object component) {94 synchronized (this) {95 for (ComponentsListener listener : listeners) {96 listener.componentReleased(element, component);97 }98 }99 }100 private <T> void register(WebElement element, T component) {101 WebElement webElement = unwrapElement(element);102 LocatorProxies.addProxyListener(webElement, this);103 synchronized (this) {104 Set<Object> elementComponents = components.computeIfAbsent(webElement, k -> new HashSet<>());105 elementComponents.add(component);106 fireComponentRegistered(element, component);107 }108 }109 @Override110 public <L extends List<T>, T> L newComponentList(Class<L> listClass, Class<T> componentClass, List<T> componentsList) {111 return instantiator.newComponentList(listClass, componentClass, componentsList);112 }113 @Override114 public <L extends List<T>, T> L asComponentList(Class<L> listClass, Class<T> componentClass,115 Iterable<WebElement> elementList) {116 L componentList = instantiator.asComponentList(listClass, componentClass, elementList);117 int i = 0;118 for (WebElement element : elementList) {119 register(element, componentList.get(i));120 i++;121 }122 return componentList;123 }124 @Override125 public void proxyElementSearch(Object proxy, ElementLocator locator) {126 // Do nothing.127 }128 @Override129 public void proxyElementFound(Object proxy, ElementLocator locator, List<WebElement> elements) {130 synchronized (this) {131 for (WebElement element : elements) {132 Set<Object> proxyComponents = components.remove(proxy);133 if (proxyComponents != null) {134 components.put(unwrapElement(element), proxyComponents);135 }136 }137 }138 }139 private WebElement unwrapElement(WebElement element) {140 if (element instanceof WrapsElement) {141 WebElement wrappedElement = getWrappedElement(element);142 if (wrappedElement != element && wrappedElement != null) { // NOPMD CompareObjectsWithEquals143 return unwrapElement(wrappedElement);144 }145 }146 return element;147 }148 /**149 * Release this manager.150 */151 public void release() {152 for (Map.Entry<WebElement, Set<Object>> elementEntry : components.entrySet()) {153 LocatorProxies.removeProxyListener(elementEntry.getKey(), this);154 for (Object component : elementEntry.getValue()) {155 fireComponentRegistered(elementEntry.getKey(), component);...

Full Screen

Full Screen

Source:ElementUtils.java Github

copy

Full Screen

...28 *29 * @param element the element to get the wrapped element of30 * @return the wrapped webelement31 */32 public static WebElement getWrappedElement(WebElement element) {33 return ((WrapsElement) element).getWrappedElement();34 }35}...

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1package org.fluentlenium.core.domain;2import org.fluentlenium.core.FluentDriver;3import org.fluentlenium.core.FluentPage;4import org.fluentlenium.core.FluentTest;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.chrome.ChromeDriver;9import org.openqa.selenium.firefox.FirefoxDriver;10import org.openqa.selenium.htmlunit.HtmlUnitDriver;11import org.openqa.selenium.support.FindBy;12import org.testng.annotations.AfterMethod;13import org.testng.annotations.BeforeMethod;14import org.testng.annotations.Test;15import java.util.List;16import static org.assertj.core.api.Assertions.assertThat;17import static org.assertj.core.api.Assertions.fail;18public class ElementUtilsTest extends FluentTest {19 @FindBy(css = "div")20 private List<WebElement> divs;21 @FindBy(css = "div")22 private List<FluentWebElement> fluentDivs;23 @FindBy(css = "div")24 private FluentList<FluentWebElement> fluentListDivs;25 @FindBy(css = "div")26 private FluentList<WebElement> listDivs;27 @FindBy(css = "div")28 private FluentWebElement fluentWebElement;29 @FindBy(css = "div")30 private WebElement webElement;31 @FindBy(css = "div")32 private FluentList<WebElement> webElements;33 @FindBy(css = "div")34 private FluentList<FluentWebElement> fluentWebElements;35 @FindBy(css = "div")36 private List<WebElement> webElementsList;37 @FindBy(css = "div")38 private List<FluentWebElement> fluentWebElementsList;39 @FindBy(css = "div")40 private FluentList<WebElement> fluentWebElementsList2;41 @FindBy(css = "div")42 private FluentList<FluentWebElement> fluentWebElementsList3;43 @FindBy(css = "div")44 private List<WebElement> webElementsList2;45 @FindBy(css = "div")46 private List<FluentWebElement> fluentWebElementsList4;47 @FindBy(css = "div")48 private FluentList<WebElement> fluentWebElementsList5;49 @FindBy(css = "div")50 private FluentList<FluentWebElement> fluentWebElementsList6;51 @FindBy(css = "div")52 private FluentList<WebElement> fluentWebElementsList7;53 @FindBy(css = "div")54 private FluentList<FluentWebElement> fluentWebElementsList8;

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1package com.fluentlenium.tutorial;2import org.fluentlenium.adapter.FluentTest;3import org.fluentlenium.core.annotation.Page;4import org.junit.Test;5import org.openqa.selenium.By;6import org.openqa.selenium.WebDriver;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.htmlunit.HtmlUnitDriver;9import org.openqa.selenium.support.FindBy;10import org.openqa.selenium.support.How;11import java.util.List;12public class 4 extends FluentTest {13 private Page1 page1;14 public WebDriver getDefaultDriver() {15 return new HtmlUnitDriver();16 }17 public void test() {18 goTo(page1);19 page1.submit();20 WebElement element = page1.getWrappedElement();21 System.out.println(element.getText());22 }23}24package com.fluentlenium.tutorial;25import org.fluentlenium.core.FluentPage;26import org.openqa.selenium.support.FindBy;27public class Page1 extends FluentPage {28 @FindBy(how = How.ID, using = "search_form_input_homepage")29 private FluentWebElement searchInput;30 @FindBy(how = How.ID, using = "search_button_homepage")31 private FluentWebElement searchButton;32 public void submit() {33 searchInput.fill().with("FluentLenium");34 searchButton.click();35 }36 public String getUrl() {37 }38}

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1package com.fluentlenium.examples;2import org.fluentlenium.adapter.FluentTest;3import org.fluentlenium.core.annotation.Page;4import org.fluentlenium.core.domain.FluentWebElement;5import org.junit.Test;6import org.openqa.selenium.By;7import org.openqa.selenium.WebElement;8import org.openqa.selenium.support.FindBy;9import static org.assertj.core.api.Assertions.assertThat;10public class ExampleTest extends FluentTest {11 private IndexPage indexPage;12 public void firstTest() {13 goTo(indexPage);14 indexPage.fillAndSubmitForm("FluentLenium", "

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1package com.mkyong.core;2import org.fluentlenium.adapter.FluentTest;3import org.fluentlenium.core.domain.FluentWebElement;4import org.junit.Test;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.htmlunit.HtmlUnitDriver;8public class ExampleTest extends FluentTest {9 public WebDriver getDefaultDriver() {10 return new HtmlUnitDriver();11 }12 public void test() {13 WebElement element = find("#lst-ib").getWrappedElement();14 FluentWebElement fluentElement = find("#lst-ib");15 element = fluentElement.getWrappedElement();16 }17}

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1package com.fluentlenium.tutorial;2import org.fluentlenium.core.domain.FluentWebElement;3import org.junit.Test;4import org.openqa.selenium.WebElement;5public class GetWrappedElement extends FluentTest {6 public void getWrappedElement() {7 FluentWebElement element = find("#lst-ib");8 WebElement wrappedElement = element.getWrappedElement();9 System.out.println("Wrapped Element: " + wrappedElement);10 }11}12Wrapped Element: org.openqa.selenium.remote.RemoteWebElement: {“element-6066-11e4-a52e-4f735466cecf”:“9a4a4a4a-4a4a-4a4a-4a4a-4a4a4a4a4a4a”}

Full Screen

Full Screen

getWrappedElement

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.adapter.FluentTest;2import org.fluentlenium.core.domain.FluentWebElement;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.chrome.ChromeDriver;5import org.openqa.selenium.chrome.ChromeOptions;6import org.openqa.selenium.remote.RemoteWebDriver;7import org.openqa.selenium.support.FindBy;8import java.util.concurrent.TimeUnit;9public class 4 extends FluentTest {10 @FindBy(css = "input[type='text']")11 private FluentWebElement inputText;12 public WebDriver newWebDriver() {13 ChromeOptions options = new ChromeOptions();14 options.addArguments("--start-maximized");15 options.addArguments("--disable-extensions");16 options.addArguments("--disable-infobars");17 options.addArguments("--disable-notifications");18 return new ChromeDriver(options);19 }20 public String getWebDriver() {21 return "webdriver.chrome.driver";22 }23 public String getWebDriverUrl() {24 return "src/test/resources/chromedriver.exe";25 }26 public void test() {27 inputText.write("Hello World");28 System.out.println(inputText.getWrappedElement().getAttribute("value"));29 }30}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run FluentLenium automation tests on LambdaTest cloud grid

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

Most used method in ElementUtils

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful