Interface SelenideElement
- All Superinterfaces:
org.openqa.selenium.interactions.Locatable
,org.openqa.selenium.SearchContext
,org.openqa.selenium.TakesScreenshot
,org.openqa.selenium.WebElement
,org.openqa.selenium.WrapsDriver
,org.openqa.selenium.WrapsElement
- All Known Subinterfaces:
SelenideAppiumElement
WebElement
with additional methods like
shouldBe(WebElementCondition...)
and shouldHave(WebElementCondition...)
-
Method Summary
Modifier and TypeMethodDescriptionSame asfind(String)
Same asfind(String, int)
$
(org.openqa.selenium.By selector) Same asfind(String)
$
(org.openqa.selenium.By selector, int index) Same asfind(String, int)
Same asfindAll(String)
$$
(org.openqa.selenium.By selector) Same asfindAll(By)
Short form ofwebDriver.findElements(thisElement, By.xpath(xpath))
Locates the first matching element inside given element using xpath locatorLocates the Nth matching element inside given element using xpath locatorLocates the closest ancestor element matching given criteria.Locates the Nth ancestor element matching given criteria.Append given text to the text field and trigger "change" event.Give this element a human-readable name Caution: you probably don't need this method.@Nullable String
Get the attribute of the element.cached()
Cache this web element.void
clear()
Clear the input fieldvoid
click()
Click the elementclick
(ClickOptions clickOption) Click the element usingClickOptions
:Same asancestor(String)
.Click with right mouse button on this element@Nullable String
Get value of attribute "data-dataAttributeName"describe()
Displays WebElement in human-readable format.Double-click the element
Before clicking, waits until element gets interactable and enabled.doubleClick
(ClickOptions clickOption) Double-click the element usingClickOptions
:$("#username").doubleClick(ClickOptions.usingJavaScript())
download()
Download file by clicking this element.download
(long timeout) Deprecated.download
(long timeout, FileFilter fileFilter) Deprecated.Use method {download(DownloadOptions)
} insteaddownload
(DownloadOptions options) download
(FileFilter fileFilter) Download file by clicking this element.dragAndDrop
(DragAndDropOptions options) Drag and drop this element to the target
Before dropping, waits until target element gets visible.<ReturnType>
@Nullable ReturnTypeExecute custom implemented command (this command will not receive any arguments throughCommand.execute(SelenideElement, WebElementSource, Object[])
when executed).<ReturnType>
@Nullable ReturnTypeExecute custom implemented command with given timeout (this command will not receive any arguments throughCommand.execute(SelenideElement, WebElementSource, Object[])
when executed).<ReturnType extends SelenideElement>
ReturnTypeexecute
(FluentCommand command) boolean
exists()
Checks if element exists true on the current page.Locates the first matching element inside given elementLocates the Nth matching element inside given elementfind
(org.openqa.selenium.By selector) Same asfind(String)
find
(org.openqa.selenium.By selector, int index) Same asfind(String, int)
Short form ofwebDriver.findElements(thisElement, By.cssSelector(cssSelector))
findAll
(org.openqa.selenium.By selector) Short form ofwebDriver.findElements(thisElement, selector)
@Nullable String
getAlias()
Element alias, which can be set withas(String text)
Usually you should not need this method, unless you are writing a custom reporting engine like Allure Reports.@Nullable String
getAttribute
(String name) @NonNull String
getCssValue
(String propertyName) Find all options from this select fieldGet the text of the element WITHOUT children.Return criteria by which this element is locatedFind (first) selected option from this select fieldFind all selected options from this select field@Nullable String
Get text of selected option in select field@Nullable String
Get value of selected option in select field@NonNull String
getText()
Get the visible text of this element, including sub-elements without leading/trailing whitespace.@Nullable String
getValue()
Get the "value" attribute of the element@NonNull org.openqa.selenium.WebElement
boolean
has
(WebElementCondition condition) immediately returns true if element matches given condition Method doesn't wait! WARNING: This method can help implementing crooks, but it is not needed for typical ui tests.boolean
has
(WebElementCondition condition, Duration timeout) highlight
(HighlightOptions options) hover()
Emulate "mouseOver" event.hover
(HoverOptions options) Emulate "mouseOver" event.Get the HTML code of the element with children.Get the text code of the element with children.boolean
is
(WebElementCondition condition) immediately returns true if element matches given condition Method doesn't wait! WARNING: This method can help implementing crooks, but it is not needed for typical ui tests.boolean
is
(WebElementCondition condition, Duration timeout) Checks if element matches given condition (with the given timeout) If matches, immediately returnstrue
If no, waits (up to given timeout), and if still no, returnsfalse
.boolean
Check if this element exists and visible.boolean
isImage()
Check if image is properly loaded.Get last child element of this element For example, $("tr").lastChild(); could give the last "td".@Nullable String
name()
Get the "name" attribute of the elementoptions()
Same asgetOptions()
parent()
Get parent element of this element (lazy evaluation) For example, $("td").parent() could give some "tr".paste()
Append text from clipboard to the text field and trigger "change" event.preceding
(int index) Get the preceding sibling element of this element For example, $("td").preceding(0) will give the first preceding sibling element of "td"press
(CharSequence... keysToPress) Press a Key(s) on Keyboard:Press ENTER.Press ESCAPE.pressTab()
Press TAB.Get content of the pseudo-elementGet the property value of the pseudo-element@Nullable File
Take screenshot of this element@Nullable BufferedImage
Take screenshot of this elementscroll
(ScrollOptions scrollOptions) Scrolls the element by a specified distance in a specified direction.Scroll element vertically to the center of viewport.scrollIntoView
(boolean alignToTop) Ask browser to scroll the element on which it's called into the visible area of the browser window.scrollIntoView
(String scrollIntoViewOptions) Ask browser to scroll the element on which it's called into the visible area of the browser window.scrollTo()
Ask browser to scroll to this elementvoid
selectOption
(int index, int... otherIndexes) Select an option from dropdown list (by index)void
selectOption
(String text, String... otherTexts) Select an option from dropdown list (by text)void
selectOptionByValue
(String value, String... otherValues) Select an option from dropdown list (by value)void
selectOptionContainingText
(String text, String... otherTexts) Select an option from dropdown list that contains given textselectRadio
(String value) Select radio buttonsetSelected
(boolean selected) Set checkbox state to CHECKED or UNCHECKED.Set value to given input element.setValue
(SetValueOptions options) Similar tosetValue(java.lang.String)
should
(WebElementCondition... condition) Sequentially checks that given element meets all given conditions.should
(WebElementCondition condition, Duration timeout) Wait until given element meets given condition (with given timeout)shouldBe
(WebElementCondition... condition) Synonym forshould(WebElementCondition...)
.shouldBe
(WebElementCondition condition, Duration timeout) Wait until given element meets given condition (with given timeout)shouldHave
(WebElementCondition... condition) Synonym forshould(WebElementCondition...)
.shouldHave
(WebElementCondition condition, Duration timeout) Wait until given element meets given condition (with given timeout)shouldNot
(WebElementCondition... condition) Sequentially checks that given element does not meet given conditions.shouldNot
(WebElementCondition condition, Duration timeout) Wait until given element meets given condition (with given timeout)shouldNotBe
(WebElementCondition... condition) Synonym forshouldNot(WebElementCondition...)
.shouldNotBe
(WebElementCondition condition, Duration timeout) Wait until given element does NOT meet given condition (with given timeout)shouldNotHave
(WebElementCondition... condition) Synonym forshouldNot(WebElementCondition...)
.shouldNotHave
(WebElementCondition condition, Duration timeout) Wait until given element does NOT meet given condition (with given timeout)sibling
(int index) Get the following sibling element of this element For example, $("td").sibling(0) will give the first following sibling element of "td"text()
Short form ofgetText()
toString()
Short description of WebElement, usually a selector.org.openqa.selenium.WebElement
type
(TypeOptions options) Similar totype(java.lang.CharSequence)
type
(CharSequence text) Mimic how real user would type in a text field Useful to work with autosuggestion dropdownunfocus()
Remove focus from this elementuploadFile
(File... file) Upload file into file upload field.uploadFromClasspath
(String... fileName) Upload file into file upload field.@Nullable String
val()
Get the "value" attribute of the element Same asgetValue()
Same assetValue(java.lang.String)
val
(SetValueOptions options) Same assetValue(SetValueOptions)
Methods inherited from interface org.openqa.selenium.interactions.Locatable
getCoordinates
Methods inherited from interface org.openqa.selenium.TakesScreenshot
getScreenshotAs
Methods inherited from interface org.openqa.selenium.WebElement
findElement, findElements, getAccessibleName, getAriaRole, getDomAttribute, getDomProperty, getLocation, getRect, getShadowRoot, getSize, getTagName, isEnabled, isSelected, sendKeys, submit
Methods inherited from interface org.openqa.selenium.WrapsDriver
getWrappedDriver
-
Method Details
-
setValue
Set value to given input element.Applicable for::
<input>
and<textarea>
.Implementation details:
If Configuration.fastSetValue is true, sets value by javascript instead of using Selenium built-in "sendKey" function and trigger "focus", "keydown", "keypress", "input", "keyup", "change" events.
In other case behavior will be:
1. WebElement.clear() 2. WebElement.sendKeys(text) 3. Trigger change event
- Parameters:
text
- Any text to enter into the text field or set by value for select/radio.- See Also:
-
val
Same assetValue(java.lang.String)
- See Also:
-
val
Same assetValue(SetValueOptions)
- See Also:
-
setValue
Similar tosetValue(java.lang.String)
- See Also:
-
type
Mimic how real user would type in a text field Useful to work with autosuggestion dropdown- See Also:
-
type
Similar totype(java.lang.CharSequence)
- Parameters:
options
- parameters specifying how exactly you want to type the text- See Also:
-
append
Append given text to the text field and trigger "change" event.Applicable for:
<input>
and<textarea>
.Implementation details:
This is the same as
1. WebElement.sendKeys(text) 2. Trigger change event
- Parameters:
text
- Any text to append into the text field.- See Also:
-
paste
Append text from clipboard to the text field and trigger "change" event. -
clear
@CanIgnoreReturnValue void clear()Clear the input fieldBasically, it's the same as
WebElement.clear()
, but it works. :)- Specified by:
clear
in interfaceorg.openqa.selenium.WebElement
- See Also:
-
pressEnter
Press ENTER. Useful for input field and textareas:$("query").val("Dear Santa").pressEnter();
Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.ENTER)
- See Also:
-
pressTab
Press TAB. Useful for input field and text areas:$("#to").val("santa@claus.fi").pressTab();
Implementation details:
Check that element is displayed and execute
WebElement.sendKeys(Keys.TAB)
- See Also:
-
unfocus
Remove focus from this element- Since:
- 7.1.0
- See Also:
-
pressEscape
Press ESCAPE. Useful for input field and textareas:$(".edit").click().pressEscape();
Implementation details:
Check that element is displayed and execute
WebElement.sendKeys(Keys.ESCAPE)
- See Also:
-
press
Press a Key(s) on Keyboard:$(".edit").press(Keys.DOWN).click();
Implementation details:
Checks that element is displayed and executes
WebElement.sendKeys(keysToPress)
Compared toWebElement.sendKeys(CharSequence...)
, this method is chainable.- See Also:
-
Press
Keys
-
getText
@NonNull String getText()Get the visible text of this element, including sub-elements without leading/trailing whitespace. NB! For "select", returns text(s) of selected option(s).- Specified by:
getText
in interfaceorg.openqa.selenium.WebElement
- Returns:
- The innerText of this element
- See Also:
-
getAlias
@Nullable String getAlias()Element alias, which can be set withas(String text)
Usually you should not need this method, unless you are writing a custom reporting engine like Allure Reports.- Returns:
- Alias of this element or null, if element alias is not set
- See Also:
-
text
String text()Short form ofgetText()
- See Also:
-
WebElement.getText()
GetText
- NOT RECOMMENDED
-
getOwnText
String getOwnText()Get the text of the element WITHOUT children.- See Also:
-
innerText
String innerText()Get the text code of the element with children.It can be used to get the text of a hidden element.
Short form of
getAttribute("textContent")
orgetAttribute("innerText")
depending on browser.- See Also:
-
innerHtml
String innerHtml()Get the HTML code of the element with children.It can be used to get the html of a hidden element.
Short form of
getAttribute("innerHTML")
.- See Also:
-
attr
Get the attribute of the element. Synonym forgetAttribute(String)
- Returns:
- null if attribute is missing
- See Also:
-
name
@Nullable String name()Get the "name" attribute of the element- Returns:
- attribute "name" value or null if attribute is missing
- See Also:
-
val
@Nullable String val()Get the "value" attribute of the element Same asgetValue()
- Returns:
- attribute "value" value or null if attribute is missing
- See Also:
-
getValue
@Nullable String getValue()Get the "value" attribute of the element- Returns:
- attribute "value" value or null if attribute is missing
- See Also:
-
pseudo
Get the property value of the pseudo-element- Parameters:
pseudoElementName
- pseudo-element name of the element, ":before", ":after", ":first-letter", ":first-line", ":selection"propertyName
- property name of the pseudo-element- Returns:
- the property value or "" if the property is missing
- See Also:
-
pseudo
Get content of the pseudo-element- Parameters:
pseudoElementName
- pseudo-element name of the element, ":before", ":after"- Returns:
- the content value or "none" if the content is missing
- See Also:
-
selectRadio
Select radio button- Parameters:
value
- value of radio button to select- Returns:
- selected "input type=radio" element
- See Also:
-
data
Get value of attribute "data-dataAttributeName"- See Also:
-
getAttribute
- Specified by:
getAttribute
in interfaceorg.openqa.selenium.WebElement
- See Also:
-
getCssValue
- Specified by:
getCssValue
in interfaceorg.openqa.selenium.WebElement
- See Also:
-
exists
boolean exists()Checks if element exists true on the current page.- Returns:
- false if element is not found, browser is closed or any WebDriver exception happened
- See Also:
-
isDisplayed
@CheckReturnValue boolean isDisplayed()Check if this element exists and visible.- Specified by:
isDisplayed
in interfaceorg.openqa.selenium.WebElement
- Returns:
- false if element does not exist, is invisible, browser is closed or any WebDriver exception happened.
- See Also:
-
is
immediately returns true if element matches given condition Method doesn't wait! WARNING: This method can help implementing crooks, but it is not needed for typical ui tests.- See Also:
-
is
Checks if element matches given condition (with the given timeout)- If matches, immediately returns
true
- If no, waits (up to given timeout), and if still no, returns
false
.
WARNING: This method can help implementing crooks, but we highly recommend to create a proper solution.
Once again: We DO NOT RECOMMEND using this method.
- Since:
- 7.1.0
- See Also:
- If matches, immediately returns
-
has
immediately returns true if element matches given condition Method doesn't wait! WARNING: This method can help implementing crooks, but it is not needed for typical ui tests.- See Also:
-
has
- See Also:
-
setSelected
Set checkbox state to CHECKED or UNCHECKED.- Parameters:
selected
- true for checked and false for unchecked- See Also:
-
should
Sequentially checks that given element meets all given conditions.IMPORTANT: If element does not match then conditions immediately, waits up to 4 seconds until element meets the conditions. It's extremely useful for dynamic content.
Timeout is configurable via
Configuration.timeout
For example:
$("#errorMessage").should(appear);
- Returns:
- Given element, useful for chaining:
$("#errorMessage").should(appear).shouldBe(enabled);
- See Also:
-
should
Wait until given element meets given condition (with given timeout)- See Also:
-
shouldHave
Synonym forshould(WebElementCondition...)
. Useful for better readability.For example:
$("#errorMessage").shouldHave(text("Hello"), text("World"));
- See Also:
-
shouldHave
Wait until given element meets given condition (with given timeout)- See Also:
-
shouldBe
Synonym forshould(WebElementCondition...)
. Useful for better readability.For example:
$("#errorMessage").shouldBe(visible, enabled);
- See Also:
-
shouldBe
Wait until given element meets given condition (with given timeout)- See Also:
-
shouldNot
Sequentially checks that given element does not meet given conditions.IMPORTANT: If element does match the conditions, waits up to 4 seconds until element does not meet the conditions. It's extremely useful for dynamic content.
Timeout is configurable via
Configuration.timeout
For example:
$("#errorMessage").should(exist);
- See Also:
-
shouldNot
Wait until given element meets given condition (with given timeout)- See Also:
-
shouldNotHave
Synonym forshouldNot(WebElementCondition...)
. Useful for better readability.For example:
$("#errorMessage").shouldNotHave(text("Exception"), text("Error"));
-
shouldNotHave
@CanIgnoreReturnValue SelenideElement shouldNotHave(WebElementCondition condition, Duration timeout) Wait until given element does NOT meet given condition (with given timeout)- See Also:
-
shouldNotBe
Synonym forshouldNot(WebElementCondition...)
. Useful for better readability.For example:
$("#errorMessage").shouldNotBe(visible, enabled);
- See Also:
-
shouldNotBe
Wait until given element does NOT meet given condition (with given timeout)- See Also:
-
toString
String toString()Short description of WebElement, usually a selector. Useful for logging and debugging. Not recommended to use for test verifications. -
describe
String describe()Displays WebElement in human-readable format. Useful for logging and debugging. Not recommended to use for test verifications. May work relatively slowly because it fetches actual element information from browser.- Returns:
- e.g. Order has been confirmed
- See Also:
-
highlight
- See Also:
-
highlight
- See Also:
-
as
Give this element a human-readable name Caution: you probably don't need this method. It's always a good idea to have the actual selector instead of "nice" description (which might be misleading or even lying).- Parameters:
alias
- a human-readable name of this element (null or empty string not allowed)- Returns:
- this element
- See Also:
-
parent
SelenideElement parent()Get parent element of this element (lazy evaluation) For example, $("td").parent() could give some "tr".- Returns:
- Parent element
- See Also:
-
sibling
Get the following sibling element of this element For example, $("td").sibling(0) will give the first following sibling element of "td"- Parameters:
index
- the index of sibling element- Returns:
- Sibling element by index
- See Also:
-
preceding
Get the preceding sibling element of this element For example, $("td").preceding(0) will give the first preceding sibling element of "td"- Parameters:
index
- the index of sibling element- Returns:
- Sibling element by index
- See Also:
-
lastChild
SelenideElement lastChild()Get last child element of this element For example, $("tr").lastChild(); could give the last "td".- See Also:
-
ancestor
Locates the closest ancestor element matching given criteria.
For example, $("td").ancestor("table") returns the closest "table" element above "td".
Same asclosest("selector", 0)
orclosest("selector")
. Examples:
$("td").ancestor("table")
will find the closest ancestor with tagtable
$("td").ancestor(".container")
will find the closest ancestor with CSS class.container
$("td").ancestor("[data-testid]")
will find the closest ancestor with attributedata-testid
$("td").ancestor("[data-testid=test-value]")
will find the closest ancestor with attribute and attribute's valuedata-testid=test-value
- Parameters:
selector
- Either HTML tag, CSS class, attribute or attribute with value.
E.g.form
,.active
,[data-testid]
,[data-testid=test-value]
- Returns:
- Matching ancestor element
- See Also:
-
ancestor
Locates the Nth ancestor element matching given criteria.
Examples:
$("td").ancestor("table", 1)
will find the 2nd ancestor with tagtable
$("td").ancestor(".container", 1)
will find the 2nd ancestor with CSS class.container
$("td").ancestor("[data-testid]", 1)
will find the 2nd ancestor with attributedata-testid
$("td").ancestor("[data-testid=test-value]", 1)
will find the 2nd ancestor with attribute and attribute's valuedata-testid=test-value
- Parameters:
selector
- Either HTML tag, CSS class, attribute or attribute with value.
E.g.form
,.active
,[data-testid]
,[data-testid=test-value]
index
- 0...N index of the ancestor. 0 is the closest, 1 is higher up the hierarchy, etc...- Returns:
- Matching ancestor element
- See Also:
-
closest
Same asancestor(String)
. Locates the closest ancestor element matching given criteria.
For example, $("td").closest("table") returns the closest "table" element above "td".
Same asancestor("selector", 0)
. Examples:
$("td").closest("table")
will find the closest ancestor with tagtable
$("td").closest(".container")
will find the closest ancestor with CSS class.container
$("td").closest("[data-testid]")
will find the closest ancestor with attributedata-testid
$("td").closest("[data-testid=test-value]")
will find the closest ancestor with attribute and attribute's valuedata-testid=test-value
- Parameters:
selector
- Either HTML tag, CSS class, attribute or attribute with value.
E.g.form
,.active
,[data-testid]
,[data-testid=test-value]
- Returns:
- Matching ancestor element
- See Also:
-
find
Locates the first matching element inside given elementShort form of
webElement.findElement(By.cssSelector(cssSelector))
- See Also:
-
find
Locates the Nth matching element inside given element- See Also:
-
find
Same asfind(String)
- See Also:
-
find
Same asfind(String, int)
- See Also:
-
$
Same asfind(String)
- See Also:
-
$
Same asfind(String, int)
- See Also:
-
$
Same asfind(String)
- See Also:
-
$
Same asfind(String, int)
- See Also:
-
$x
Locates the first matching element inside given element using xpath locatorShort form of
webElement.findElement(By.xpath(xpathLocator))
- See Also:
-
$x
Locates the Nth matching element inside given element using xpath locator- See Also:
-
findAll
Short form ofwebDriver.findElements(thisElement, By.cssSelector(cssSelector))
For example,
$("#multirowTable").findAll("tr.active").shouldHave(size(2));
- Returns:
- list of elements inside given element matching given CSS selector
- See Also:
-
findAll
Short form ofwebDriver.findElements(thisElement, selector)
For example,
$("#multirowTable").findAll(By.className("active")).shouldHave(size(2));
- Returns:
- list of elements inside given element matching given criteria
- See Also:
-
$$
Same asfindAll(String)
- See Also:
-
$$
Same asfindAll(By)
-
$$x
Short form ofwebDriver.findElements(thisElement, By.xpath(xpath))
For example,
$("#multirowTable").$$x("./input").shouldHave(size(2));
- Returns:
- list of elements inside given element matching given xpath locator
- See Also:
-
uploadFromClasspath
Upload file into file upload field. File is searched from classpath.Multiple file upload is also supported. Just pass as many file names as you wish.
Applicable for:
<input type="file">
.- Parameters:
fileName
- name of the file or the relative path in classpath e.g. "files/1.pfd"- Returns:
- the object of the first file uploaded
- Throws:
IllegalArgumentException
- if any of the files is not found- See Also:
-
uploadFile
Upload file into file upload field.Multiple file upload is also supported. Just pass as many files as you wish.
Applicable for:
<input type="file">
.- Parameters:
file
- file object(s)- Returns:
- the object of the first file uploaded
- Throws:
IllegalArgumentException
- if any of the files is not found, or other errors- See Also:
-
selectOption
void selectOption(int index, int... otherIndexes) Select an option from dropdown list (by index)Applicable for:
<select> <option>...<option> </select>
- Parameters:
index
- from 0 to N (0 means first option)otherIndexes
- other indexes (if you need to select multiple options)- See Also:
-
selectOption
Select an option from dropdown list (by text)Applicable for:
<select> <option>...<option> </select>
- Parameters:
text
- visible text of optionotherTexts
- other texts (if you need to select multiple options)- See Also:
-
selectOptionContainingText
Select an option from dropdown list that contains given textApplicable for:
<select> <option>...<option> </select>
- Parameters:
text
- substring of visible text of optionotherTexts
- other texts (if you need to select multiple options)- See Also:
-
selectOptionByValue
Select an option from dropdown list (by value)Applicable for:
<select> <option>...<option> </select>
- Parameters:
value
- "value" attribute of optionotherValues
- other values (if you need to select multiple options)- See Also:
-
getSelectedOption
Find (first) selected option from this select fieldApplicable for:
<select> <option>...<option> </select>
- Returns:
- WebElement for selected <option> element
- Throws:
org.openqa.selenium.NoSuchElementException
- See Also:
-
getSelectedOptions
ElementsCollection getSelectedOptions()Find all selected options from this select fieldApplicable for:
<select> <option>...<option> </select>
- Returns:
- ElementsCollection for selected <option> elements (empty list if no options are selected)
- See Also:
-
getOptions
ElementsCollection getOptions()Find all options from this select fieldApplicable for:
<select> <option>...<option> </select>
- Returns:
- ElementsCollection for all <option> elements
- See Also:
-
options
ElementsCollection options()Same asgetOptions()
-
getSelectedOptionValue
@Nullable String getSelectedOptionValue()Get value of selected option in select fieldApplicable for:
<select> <option>...<option> </select>
- Returns:
- null if the selected option doesn't have "value" attribute (or the select doesn't have options at all)
- See Also:
-
getSelectedOptionText
@Nullable String getSelectedOptionText()Get text of selected option in select fieldApplicable for:
<select> <option>...<option> </select>
- Returns:
- null if there is no selected options (or the select doesn't have options at all)
- Throws:
IllegalArgumentException
- if the element type is not<select/>
- See Also:
-
scrollTo
Ask browser to scroll to this element- See Also:
-
scrollIntoView
Ask browser to scroll the element on which it's called into the visible area of the browser window.If alignToTop boolean value is true - the top of the element will be aligned to the top.
If alignToTop boolean value is false - the bottom of the element will be aligned to the bottom.
Usage:
element.scrollIntoView(true); // Corresponds to scrollIntoViewOptions: {block: "start", inline: "nearest"} element.scrollIntoView(false); // Corresponds to scrollIntoViewOptions: {block: "end", inline: "nearest"}
- Parameters:
alignToTop
- boolean value that indicate how element will be aligned to the visible area of the scrollable ancestor.- See Also:
-
scrollIntoView
Ask browser to scroll the element on which it's called into the visible area of the browser window.scrollIntoViewOptions: * behavior (optional) - Defines the transition animation 1. auto (default) 2. instant 3. smooth * block (optional) 1. start (default) 2. center 3. end 4. nearest * inline 1. start 2. center 3. end 4. nearest (default)
Usage:element.scrollIntoView("{block: \"end\"}"); element.scrollIntoView("{behavior: \"instant\", block: \"end\", inline: \"nearest\"}");
- Parameters:
scrollIntoViewOptions
- is an object with the align properties: behavior, block and inline.- See Also:
-
scrollIntoCenter
Scroll element vertically to the center of viewport. Same as$.scrollIntoView("{block: 'center'}")
- Since:
- 7.6.0
- See Also:
-
scroll
Scrolls the element by a specified distance in a specified direction.It takes
ScrollOptions
to specify the direction, distance and other options. For example, if you want to scroll the element down by 100 pixels, you can do:element.scroll(ScrollOptions.direction(ScrollDirection.DOWN).distance(100))
element.scroll(ScrollOptions.direction(ScrollDirection.RIGHT).distance(250))
- Parameters:
scrollOptions
- direction, distance etc.- See Also:
-
download
Download file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }
.- Throws:
RuntimeException
- if 50x status code was returned from serverFileNotDownloadedError
- if 40x status code was returned from server- See Also:
-
download
Deprecated.Use method {download(DownloadOptions)
} insteadDownload file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }
.- Parameters:
timeout
- download operations timeout.- Throws:
RuntimeException
- if 50x status code was returned from serverFileNotDownloadedError
- if 40x status code was returned from server- See Also:
-
download
Download file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }
.- Parameters:
fileFilter
- Criteria for defining which file is expected (FileFilters.withName(String)
,FileFilters.withNameMatching(String)
,FileFilters.withName(String)
).- Throws:
RuntimeException
- if 50x status code was returned from serverFileNotDownloadedError
- if 40x status code was returned from server, or the downloaded file didn't match given filter.- See Also:
-
download
Deprecated.Use method {download(DownloadOptions)
} insteadDownload file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }
.- Parameters:
timeout
- download operations timeout.fileFilter
- Criteria for defining which file is expected (FileFilters.withName(String)
,FileFilters.withNameMatching(String)
,FileFilters.withName(String)
).- Throws:
RuntimeException
- if 50x status code was returned from serverFileNotDownloadedError
- if 40x status code was returned from server, or the downloaded file didn't match given filter.- See Also:
-
download
- Throws:
FileNotDownloadedError
- See Also:
-
getSearchCriteria
String getSearchCriteria()Return criteria by which this element is located- Returns:
- e.g. "#multirowTable.findBy(text 'INVALID-TEXT')/valid-selector"
- See Also:
-
toWebElement
org.openqa.selenium.WebElement toWebElement()- Returns:
- the original Selenium
WebElement
wrapped by this object - Throws:
org.openqa.selenium.NoSuchElementException
- if element does not exist (without waiting for the element)- See Also:
-
getWrappedElement
@NonNull org.openqa.selenium.WebElement getWrappedElement()- Specified by:
getWrappedElement
in interfaceorg.openqa.selenium.WrapsElement
- Returns:
- Underlying
WebElement
- Throws:
ElementNotFound
- if element does not exist (after waiting for N seconds)- See Also:
-
cached
SelenideElement cached()Cache this web element. The following calls to this object will not re-load this element from browser.- See Also:
-
click
Click the element usingClickOptions
:$("#username").click(ClickOptions.usingJavaScript())
$("#username").click(usingJavaScript().offset(123, 222))
- Returns:
- this element
- See Also:
-
click
@CanIgnoreReturnValue void click()Click the elementBy default, it uses default Selenium method click.
But it uses JavaScript method to click if
com.codeborne.selenide.Configuration#clickViaJs
is defined. It may be helpful for testing in Internet Explorer where native click doesn't always work correctly.
Before clicking, waits until element gets interactable and enabled.- Specified by:
click
in interfaceorg.openqa.selenium.WebElement
- See Also:
-
contextClick
Click with right mouse button on this element- Returns:
- this element
- See Also:
-
doubleClick
Double-click the element
Before clicking, waits until element gets interactable and enabled.- Returns:
- this element
- See Also:
-
doubleClick
Double-click the element usingClickOptions
:$("#username").doubleClick(ClickOptions.usingJavaScript())
You can specify a relative offset from the center of the element inside ClickOptions: e.g.
$("#username").doubleClick(usingJavaScript().offset(123, 222))
Before clicking, waits until element gets interactable and enabled.- Returns:
- this element
- See Also:
-
hover
Emulate "mouseOver" event. In other words, move mouse cursor over this element (without clicking it).- Returns:
- this element
- See Also:
-
hover
Emulate "mouseOver" event. In other words, move mouse cursor over this element (without clicking it).- Parameters:
options
- optional hover parameters (offset etc)- Returns:
- this element
- See Also:
-
dragAndDrop
Drag and drop this element to the target
Before dropping, waits until target element gets visible.
Examples:
using a CSS selector defining the target element:
$("#element").dragAndDrop(to("#target"))
using a SelenideElement defining the target element:
$("#element").dragAndDrop(to($("#target")))
define which way it will be executed:
usingJavaScript
(by default):
$("#element").dragAndDrop(to("#target").usingJS())
usingActions
:
$("#element").dragAndDrop(to("#target").usingSeleniumActions())
/ *- Parameters:
options
- drag and drop options to define target and which way it will be executed- Returns:
- this element
- See Also:
-
execute
Execute custom implemented command (this command will not receive any arguments throughCommand.execute(SelenideElement, WebElementSource, Object[])
when executed). -
execute
@CanIgnoreReturnValue <ReturnType extends SelenideElement> ReturnType execute(FluentCommand command) -
execute
@CanIgnoreReturnValue <ReturnType> @Nullable ReturnType execute(Command<ReturnType> command, Duration timeout) Execute custom implemented command with given timeout (this command will not receive any arguments throughCommand.execute(SelenideElement, WebElementSource, Object[])
when executed). -
isImage
boolean isImage()Check if image is properly loaded.Applicable for:
<img src="...">
.- Throws:
IllegalArgumentException
- if argument is not an "img" element- See Also:
-
screenshot
@Nullable File screenshot()Take screenshot of this element- Returns:
- file with screenshot (*.png) or null if Selenide failed to take a screenshot (due to some technical problem)
- See Also:
-
screenshotAsImage
@Nullable BufferedImage screenshotAsImage()Take screenshot of this element- Returns:
- buffered image with screenshot
- See Also:
-
download(DownloadOptions)
} instead