Package org.fluentlenium.core.domain
Class FluentWebElement
- java.lang.Object
-
- org.fluentlenium.core.domain.Component
-
- org.fluentlenium.core.domain.FluentWebElement
-
- All Implemented Interfaces:
FluentActions<FluentWebElement,FluentWebElement>,FluentJavascriptActions,HookControl<FluentWebElement>,FluentLabel<FluentWebElement>,FluentProxyState<FluentWebElement>,SearchControl<FluentWebElement>,org.openqa.selenium.internal.WrapsElement,org.openqa.selenium.WrapsElement
public class FluentWebElement extends Component implements org.openqa.selenium.internal.WrapsElement, FluentActions<FluentWebElement,FluentWebElement>, FluentProxyState<FluentWebElement>, SearchControl<FluentWebElement>, HookControl<FluentWebElement>, FluentLabel<FluentWebElement>
Wraps a SeleniumWebElement. It provides an enhanced API to control selenium element.
-
-
Field Summary
-
Fields inherited from class org.fluentlenium.core.domain.Component
control, instantiator, webElement
-
-
Constructor Summary
Constructors Constructor Description FluentWebElement(org.openqa.selenium.WebElement element, FluentControl control, ComponentInstantiator instantiator)Creates a new fluent web element.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description FluentList<FluentWebElement>$(java.util.List<org.openqa.selenium.WebElement> rawElements)Wrap raw selenium elements into a list of elements.<T> Tas(java.lang.Class<T> componentClass)Wrap all underlying elements in a component.FluentList<FluentWebElement>asList()Converts this element as a single element list.java.lang.Stringattribute(java.lang.String name)return any value of custom attribute (generated=true will return "true" if attribute("generated") is called.FluentWaitElementawait()Build a wait object to wait for a condition of this element.Domaxes()Deprecated.Usedom()instead.FluentWebElementclear()Clear the elementFluentWebElementclearReactInput()Clear React input using Backspace onlyFluentWebElementclick()Perform a click.booleanclickable()Check that this element is visible and enabled such that you can click it.FluentConditionsconditions()Get a conditions object used to verify condition on this element.FluentWebElementcontextClick()Perform a context click.java.lang.StringcssValue(java.lang.String propertyName)Get the value of a given CSS property.booleandisplayed()return true if the element is displayed, other way return falseDomdom()XPath Axes accessor (parent, ancestors, preceding, following, ...).FluentWebElementdoubleClick()Perform a double click.FluentWebElementel(org.openqa.selenium.WebElement rawElement)Wrap existing raw selenium element into an element.booleanenabled()return true if the element is enabled, other way return falseFillfill()Construct a Fill Builder in order to allow easy fill of visible input fields.FillSelectfillSelect()Construct a Fill Select Builder in order to allow easy fill of visible input fields.FluentList<FluentWebElement>find(java.lang.String selector, SearchFilter... filters)Find list of elements with CSS selector and filters.FluentList<FluentWebElement>find(java.util.List<org.openqa.selenium.WebElement> rawElements)Wrap raw selenium elements into a list of elements.FluentList<FluentWebElement>find(SearchFilter... filters)Find list of elements with filters.FluentList<FluentWebElement>find(org.openqa.selenium.By locator, SearchFilter... filters)Find list of elements with Selenium locator and filters.FluentWebElementframe()Select a frame using this element.org.openqa.selenium.WebElementgetElement()return the webElementFluentLabel<FluentWebElement>getLabel()org.openqa.selenium.WebElementgetWrappedElement()java.lang.Stringhtml()Get the HTML of a the elementjava.lang.Stringid()return the id of the elementsKeyboardElementActionskeyboard()Execute keyboard actions on the elementbooleanloaded()Check if the element is loaded.FluentWebElementmodifyAttribute(java.lang.String attributeName, java.lang.String attributeValue)Modifies element attributesMouseElementActionsmouse()Execute mouse actions on the elementjava.lang.Stringname()return the name of the elementFluentWebElementnoHook()Disable all hooks from actual element.FluentWebElementnoHook(java.lang.Class<? extends FluentHook>... hooks)Disable given hook from actual element.<R> RnoHook(java.lang.Class<? extends FluentHook> hook, java.util.function.Function<FluentWebElement,R> function)Invoke a function with no hook.<R> RnoHook(java.util.function.Function<FluentWebElement,R> function)Invoke a function with no hook.FluentWebElementnoHookInstance()Creates a new element locator instance with all hooks disabled.FluentWebElementnoHookInstance(java.lang.Class<? extends FluentHook>... hooks)Creates a new element locator instance with given hook disabled.FluentWebElementnow()Search for the element now, actually performing the search on theWebDriver.FluentWebElementnow(boolean force)Search for the element now, actually performing the search on theWebDriver.java.util.Optional<FluentWebElement>optional()Builds an optional.booleanpresent()Check if the element is present in the DOM.FluentWebElementreset()Reset the element.FluentWebElementrestoreHooks()Retore hooks that were defined initially.FluentWebElementscrollIntoView()Scrolls the current element into the visible area of the browser window.FluentWebElementscrollIntoView(boolean alignWithTop)Scrolls the current element into the visible area of the browser window.FluentWebElementscrollToCenter()Scrolls center of the current element into the visible area of the browser window, respecting window size.booleanselected()return true if the element is selected, other way falseorg.openqa.selenium.Dimensionsize()return the size of the elementbooleanstale()Check that this element is no longer attached to the DOM.FluentWebElementsubmit()Submit the elementjava.lang.StringtagName()return the tag namejava.lang.Stringtext()return the visible text of the elementjava.lang.StringtextContent()return the text content of the element (even invisible through textContent attribute)java.lang.StringtoString()java.lang.Stringvalue()return the value of the elements<O,H extends FluentHook<O>>
FluentWebElementwithHook(java.lang.Class<H> hook)Enable a hook with default options.<O,H extends FluentHook<O>>
FluentWebElementwithHook(java.lang.Class<H> hook, O options)Enable a hook with given options.FluentWebElementwithLabel(java.lang.String label)Apply a label that will be displayed as the representation of this object for error message.FluentWebElementwithLabelHint(java.lang.String... labelHint)Add a label hint that will be appended to the representation of this object for error message.FluentWebElementwrite(java.lang.String... text)Set the text element
-
-
-
Constructor Detail
-
FluentWebElement
public FluentWebElement(org.openqa.selenium.WebElement element, FluentControl control, ComponentInstantiator instantiator)Creates a new fluent web element.- Parameters:
element- underlying elementcontrol- control interfaceinstantiator- component instantiator
-
-
Method Detail
-
getLabel
public FluentLabel<FluentWebElement> getLabel()
-
click
public FluentWebElement click()
Description copied from interface:FluentActionsPerform a click.- Specified by:
clickin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- this object reference to chain methods calls
- See Also:
WebElement.click()
-
doubleClick
public FluentWebElement doubleClick()
Description copied from interface:FluentActionsPerform a double click.- Specified by:
doubleClickin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- this object reference to chain methods calls
-
contextClick
public FluentWebElement contextClick()
Description copied from interface:FluentActionsPerform a context click.- Specified by:
contextClickin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- this object reference to chain methods calls
-
present
public boolean present()
Description copied from interface:FluentProxyStateCheck if the element is present in the DOM.- Specified by:
presentin interfaceFluentProxyState<FluentWebElement>- Returns:
- true if the element is present, false otherwise
-
now
public FluentWebElement now()
Description copied from interface:FluentProxyStateSearch for the element now, actually performing the search on theWebDriver.It has no effect if the element is already loaded.
- Specified by:
nowin interfaceFluentProxyState<FluentWebElement>- Returns:
- this object reference to chain calls.
-
now
public FluentWebElement now(boolean force)
Description copied from interface:FluentProxyStateSearch for the element now, actually performing the search on theWebDriver.It has no effect if the element is already loaded.
- Specified by:
nowin interfaceFluentProxyState<FluentWebElement>- Parameters:
force- force the search even if element is already loaded- Returns:
- this object reference to chain calls.
-
reset
public FluentWebElement reset()
Description copied from interface:FluentProxyStateReset the element. Subsequent calls will perform the search again, instead of using the cached result.- Specified by:
resetin interfaceFluentProxyState<FluentWebElement>- Returns:
- this object reference to chain calls.
-
loaded
public boolean loaded()
Description copied from interface:FluentProxyStateCheck if the element is loaded.- Specified by:
loadedin interfaceFluentProxyState<FluentWebElement>- Returns:
- true if the element is loaded, false otherwise
-
axes
@Deprecated public Dom axes()
Deprecated.Usedom()instead.XPath Axes accessor (parent, ancestors, preceding, following, ...).- Returns:
- object to perform XPath Axes transformations.
-
dom
public Dom dom()
XPath Axes accessor (parent, ancestors, preceding, following, ...).- Returns:
- object to perform XPath Axes transformations.
-
conditions
public FluentConditions conditions()
Get a conditions object used to verify condition on this element.- Returns:
- conditions object
-
await
public FluentWaitElement await()
Build a wait object to wait for a condition of this element.- Returns:
- a wait object
-
mouse
public MouseElementActions mouse()
Execute mouse actions on the element- Returns:
- mouse actions object
-
keyboard
public KeyboardElementActions keyboard()
Execute keyboard actions on the element- Returns:
- keyboard actions object
-
as
public <T> T as(java.lang.Class<T> componentClass)
Wrap all underlying elements in a component.- Type Parameters:
T- type of component- Parameters:
componentClass- component class- Returns:
- element as component.
-
clear
public FluentWebElement clear()
Clear the element- Returns:
- fluent web element
-
clearReactInput
public FluentWebElement clearReactInput()
Clear React input using Backspace only- Returns:
- fluent web element
-
submit
public FluentWebElement submit()
Submit the element- Specified by:
submitin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- fluent web element
- See Also:
WebElement.submit()
-
write
public FluentWebElement write(java.lang.String... text)
Set the text element- Specified by:
writein interfaceFluentActions<FluentWebElement,FluentWebElement>- Parameters:
text- value to set- Returns:
- fluent web element
- See Also:
WebElement.sendKeys(CharSequence...)
-
name
public java.lang.String name()
return the name of the element- Returns:
- name of the element
-
attribute
public java.lang.String attribute(java.lang.String name)
return any value of custom attribute (generated=true will return "true" if attribute("generated") is called.- Parameters:
name- custom attribute name- Returns:
- name value
- See Also:
WebElement.getAttribute(String)
-
cssValue
public java.lang.String cssValue(java.lang.String propertyName)
Get the value of a given CSS property.- Parameters:
propertyName- the css property name of the element- Returns:
- The current, computed value of the property.
- See Also:
WebElement.getCssValue(String)
-
id
public java.lang.String id()
return the id of the elements- Returns:
- id of element
-
text
public java.lang.String text()
return the visible text of the element- Returns:
- text of element
- See Also:
WebElement.getText()
-
textContent
public java.lang.String textContent()
return the text content of the element (even invisible through textContent attribute)- Returns:
- text content of element
-
value
public java.lang.String value()
return the value of the elements- Returns:
- value of attribute
-
displayed
public boolean displayed()
return true if the element is displayed, other way return false- Returns:
- boolean value of displayed check
- See Also:
WebElement.isDisplayed()
-
enabled
public boolean enabled()
return true if the element is enabled, other way return false- Returns:
- boolean value of enabled check
- See Also:
WebElement.isEnabled()
-
selected
public boolean selected()
return true if the element is selected, other way false- Returns:
- boolean value of selected check
- See Also:
WebElement.isSelected()
-
clickable
public boolean clickable()
Check that this element is visible and enabled such that you can click it.- Returns:
- true if the element can be clicked, false otherwise.
-
stale
public boolean stale()
Check that this element is no longer attached to the DOM.- Returns:
- false is the element is still attached to the DOM, true otherwise.
-
tagName
public java.lang.String tagName()
return the tag name- Returns:
- string value of tag name
- See Also:
WebElement.getTagName()
-
getElement
public org.openqa.selenium.WebElement getElement()
return the webElement- Returns:
- web element
-
getWrappedElement
public org.openqa.selenium.WebElement getWrappedElement()
- Specified by:
getWrappedElementin interfaceorg.openqa.selenium.WrapsElement
-
size
public org.openqa.selenium.Dimension size()
return the size of the element- Returns:
- dimension/size of element
- See Also:
WebElement.getSize()
-
asList
public FluentList<FluentWebElement> asList()
Converts this element as a single element list.- Returns:
- list of element
-
find
public FluentList<FluentWebElement> find(org.openqa.selenium.By locator, SearchFilter... filters)
Description copied from interface:SearchControlFind list of elements with Selenium locator and filters.- Specified by:
findin interfaceSearchControl<FluentWebElement>- Parameters:
locator- elements locatorfilters- filters set- Returns:
- list of elements
-
find
public FluentList<FluentWebElement> find(java.lang.String selector, SearchFilter... filters)
Description copied from interface:SearchControlFind list of elements with CSS selector and filters.- Specified by:
findin interfaceSearchControl<FluentWebElement>- Parameters:
selector- CSS selectorfilters- set of filters- Returns:
- list of element
-
find
public FluentList<FluentWebElement> find(SearchFilter... filters)
Description copied from interface:SearchControlFind list of elements with filters.- Specified by:
findin interfaceSearchControl<FluentWebElement>- Parameters:
filters- set of filters in the current context- Returns:
- list of elements
-
find
public FluentList<FluentWebElement> find(java.util.List<org.openqa.selenium.WebElement> rawElements)
Description copied from interface:SearchControlWrap raw selenium elements into a list of elements.- Specified by:
findin interfaceSearchControl<FluentWebElement>- Parameters:
rawElements- raw selenium elements- Returns:
- list of element
-
$
public FluentList<FluentWebElement> $(java.util.List<org.openqa.selenium.WebElement> rawElements)
Description copied from interface:SearchControlWrap raw selenium elements into a list of elements.- Specified by:
$in interfaceSearchControl<FluentWebElement>- Parameters:
rawElements- raw selenium elements- Returns:
- list of element
-
el
public FluentWebElement el(org.openqa.selenium.WebElement rawElement)
Description copied from interface:SearchControlWrap existing raw selenium element into an element.- Specified by:
elin interfaceSearchControl<FluentWebElement>- Parameters:
rawElement- raw selenium element- Returns:
- element
-
html
public java.lang.String html()
Get the HTML of a the element- Returns:
- the underlying html content
-
fill
public Fill fill()
Description copied from interface:FluentActionsConstruct a Fill Builder in order to allow easy fill of visible input fields.- Specified by:
fillin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- Fill builder
-
fillSelect
public FillSelect fillSelect()
Description copied from interface:FluentActionsConstruct a Fill Select Builder in order to allow easy fill of visible input fields.- Specified by:
fillSelectin interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- Fill select builder
-
frame
public FluentWebElement frame()
Description copied from interface:FluentActionsSelect a frame using this element.- Specified by:
framein interfaceFluentActions<FluentWebElement,FluentWebElement>- Returns:
- this object reference to chain methods calls.
-
optional
public java.util.Optional<FluentWebElement> optional()
Description copied from interface:FluentProxyStateBuilds an optional. If underlying element is lazy, search will be perfomed when invoking this method.- Specified by:
optionalin interfaceFluentProxyState<FluentWebElement>- Returns:
- An optional wrapping this.
- See Also:
FluentProxyState.present(),FluentProxyState.now()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
noHook
public <R> R noHook(java.lang.Class<? extends FluentHook> hook, java.util.function.Function<FluentWebElement,R> function)
Description copied from interface:HookControlInvoke a function with no hook.- Specified by:
noHookin interfaceHookControl<FluentWebElement>- Type Parameters:
R- return type- Parameters:
hook- hook class to disablefunction- function to invoke- Returns:
- return value of the given function
-
withHook
public <O,H extends FluentHook<O>> FluentWebElement withHook(java.lang.Class<H> hook, O options)
Description copied from interface:HookControlEnable a hook with given options.- Specified by:
withHookin interfaceHookControl<FluentWebElement>- Type Parameters:
O- Type of the hookH- Type of the hook options- Parameters:
hook- hook class to enableoptions- hook options to apply- Returns:
- this object reference to chain calls
-
withHook
public <O,H extends FluentHook<O>> FluentWebElement withHook(java.lang.Class<H> hook)
Description copied from interface:HookControlEnable a hook with default options.- Specified by:
withHookin interfaceHookControl<FluentWebElement>- Type Parameters:
O- Type of the hookH- Type of the hook options- Parameters:
hook- hook class to enable- Returns:
- this object reference to chain calls
-
noHook
public FluentWebElement noHook(java.lang.Class<? extends FluentHook>... hooks)
Description copied from interface:HookControlDisable given hook from actual element.- Specified by:
noHookin interfaceHookControl<FluentWebElement>- Parameters:
hooks- hook classes to disable- Returns:
- this object reference to chain calls
-
noHook
public <R> R noHook(java.util.function.Function<FluentWebElement,R> function)
Description copied from interface:HookControlInvoke a function with no hook.- Specified by:
noHookin interfaceHookControl<FluentWebElement>- Type Parameters:
R- return type- Parameters:
function- function to invoke- Returns:
- return value of the given function
-
noHookInstance
public FluentWebElement noHookInstance(java.lang.Class<? extends FluentHook>... hooks)
Description copied from interface:HookControlCreates a new element locator instance with given hook disabled.- Specified by:
noHookInstancein interfaceHookControl<FluentWebElement>- Parameters:
hooks- hook classes to disable- Returns:
- new element locator with hook disabled.
-
restoreHooks
public FluentWebElement restoreHooks()
Description copied from interface:HookControlRetore hooks that were defined initially.- Specified by:
restoreHooksin interfaceHookControl<FluentWebElement>- Returns:
- this object reference to chain calls
-
noHookInstance
public FluentWebElement noHookInstance()
Description copied from interface:HookControlCreates a new element locator instance with all hooks disabled.- Specified by:
noHookInstancein interfaceHookControl<FluentWebElement>- Returns:
- new element locator with hook disabled.
-
noHook
public FluentWebElement noHook()
Description copied from interface:HookControlDisable all hooks from actual element.- Specified by:
noHookin interfaceHookControl<FluentWebElement>- Returns:
- this object reference to chain calls
-
scrollToCenter
public FluentWebElement scrollToCenter()
Description copied from interface:FluentJavascriptActionsScrolls center of the current element into the visible area of the browser window, respecting window size.- Specified by:
scrollToCenterin interfaceFluentJavascriptActions- Returns:
- this object reference to chain methods calls
-
scrollIntoView
public FluentWebElement scrollIntoView()
Description copied from interface:FluentJavascriptActionsScrolls the current element into the visible area of the browser window.- Specified by:
scrollIntoViewin interfaceFluentJavascriptActions- Returns:
- this object reference to chain methods calls
- See Also:
- element.scrollIntoView
-
scrollIntoView
public FluentWebElement scrollIntoView(boolean alignWithTop)
Description copied from interface:FluentJavascriptActionsScrolls the current element into the visible area of the browser window.- Specified by:
scrollIntoViewin interfaceFluentJavascriptActions- Parameters:
alignWithTop- If true, the top of the element will be aligned to the top of the visible area of the scrollable ancestor. If false, the bottom of the element will be aligned to the bottom of the visible area of the scrollable ancestor.- Returns:
- this object reference to chain methods calls
- See Also:
- element.scrollIntoView
-
modifyAttribute
public FluentWebElement modifyAttribute(java.lang.String attributeName, java.lang.String attributeValue)
Description copied from interface:FluentJavascriptActionsModifies element attributes- Specified by:
modifyAttributein interfaceFluentJavascriptActions- Returns:
- this object reference to chain methods calls
-
withLabelHint
public FluentWebElement withLabelHint(java.lang.String... labelHint)
Description copied from interface:FluentLabelAdd a label hint that will be appended to the representation of this object for error message.- Specified by:
withLabelHintin interfaceFluentLabel<FluentWebElement>- Parameters:
labelHint- label hints to add- Returns:
- reference to this object to chain calls
-
withLabel
public FluentWebElement withLabel(java.lang.String label)
Description copied from interface:FluentLabelApply a label that will be displayed as the representation of this object for error message.- Specified by:
withLabelin interfaceFluentLabel<FluentWebElement>- Parameters:
label- label to use- Returns:
- reference to this object to chain calls
-
-