Interface SelenideElement
-
- All Superinterfaces:
org.openqa.selenium.internal.HasIdentity,org.openqa.selenium.interactions.Locatable,org.openqa.selenium.SearchContext,org.openqa.selenium.TakesScreenshot,org.openqa.selenium.WebElement,org.openqa.selenium.WrapsDriver,org.openqa.selenium.internal.WrapsElement,org.openqa.selenium.WrapsElement
@ParametersAreNonnullByDefault public interface SelenideElement extends org.openqa.selenium.WebElement, org.openqa.selenium.WrapsDriver, org.openqa.selenium.internal.WrapsElement, org.openqa.selenium.interactions.Locatable, org.openqa.selenium.TakesScreenshot, org.openqa.selenium.internal.HasIdentityWrapper aroundWebElementwith additional methods likeshouldBe(Condition...)andshouldHave(Condition...)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description SelenideElement$(java.lang.String cssSelector)Same asfind(String)SelenideElement$(java.lang.String cssSelector, int index)Same asfind(String, int)SelenideElement$(org.openqa.selenium.By selector)Same asfind(String)SelenideElement$(org.openqa.selenium.By selector, int index)Same asfind(String, int)ElementsCollection$$(java.lang.String cssSelector)Same asfindAll(String)ElementsCollection$$(org.openqa.selenium.By selector)Same asfindAll(By)ElementsCollection$$x(java.lang.String xpath)Short form ofwebDriver.findElements(thisElement, By.xpath(xpath))SelenideElement$x(java.lang.String xpath)Locates the first matching element inside given element using xpath locatorSelenideElement$x(java.lang.String xpath, int index)Locates the Nth matching element inside given element using xpath locatorSelenideElementappend(java.lang.String text)Append given text to the text field and trigger "change" event.SelenideElementas(java.lang.String alias)Give this element a human-readable name Caution: you probably don't need this method.java.lang.Stringattr(java.lang.String attributeName)Get the attribute of the element.voidclick()Click the elementvoidclick(int offsetX, int offsetY)Deprecated.useclick(ClickOptions)with offsetsvoidclick(ClickOptions clickOption)Click the element usingClickOptions:$("#username").click(ClickOptions.usingJavaScript())SelenideElementclosest(java.lang.String tagOrClass)Locates closes ancestor element matching given criteria For example, $("td").closest("table") could give some "table".SelenideElementcontextClick()Click with right mouse button on this elementjava.lang.Stringdata(java.lang.String dataAttributeName)Get value of attribute "data-dataAttributeName"SelenideElementdoubleClick()Double click the elementjava.io.Filedownload()Download file by clicking this element.java.io.Filedownload(long timeout)Download file by clicking this element.java.io.Filedownload(long timeout, FileFilter fileFilter)Download file by clicking this element.java.io.Filedownload(DownloadOptions options)java.io.Filedownload(FileFilter fileFilter)Download file by clicking this element.SelenideElementdragAndDropTo(java.lang.String targetCssSelector)Drag and drop this element to the targetSelenideElementdragAndDropTo(java.lang.String targetCssSelector, DragAndDropOptions options)Drag and drop this element to the target via JS script see resources/drag_and_drop_scriptSelenideElementdragAndDropTo(org.openqa.selenium.WebElement target)Drag and drop this element to the target<ReturnType>
ReturnTypeexecute(Command<ReturnType> command)Execute custom implemented commandbooleanexists()Checks if element exists true on the current page.SelenideElementfind(java.lang.String cssSelector)Locates the first matching element inside given elementSelenideElementfind(java.lang.String cssSelector, int index)Locates the Nth matching element inside given elementSelenideElementfind(org.openqa.selenium.By selector)Same asfind(String)SelenideElementfind(org.openqa.selenium.By selector, int index)Same asfind(String, int)ElementsCollectionfindAll(java.lang.String cssSelector)Short form ofwebDriver.findElements(thisElement, By.cssSelector(cssSelector))ElementsCollectionfindAll(org.openqa.selenium.By selector)Short form ofwebDriver.findElements(thisElement, selector)java.lang.StringgetAlias()Element alias, which can be set withas(String text)java.lang.StringgetAttribute(java.lang.String name)java.lang.StringgetCssValue(java.lang.String propertyName)java.lang.StringgetOwnText()Get the text of the element WITHOUT children.java.lang.StringgetSearchCriteria()Return criteria by which this element is locatedSelenideElementgetSelectedOption()Find (first) selected option from this select fieldElementsCollectiongetSelectedOptions()Find all selected options from this select fieldjava.lang.StringgetSelectedText()Get text of selected option in select fieldjava.lang.StringgetSelectedValue()Get value of selected option in select fieldjava.lang.StringgetText()Get the visible text of this element, including sub-elements without leading/trailing whitespace.java.lang.StringgetValue()Get the "value" attribute of the elementorg.openqa.selenium.WebElementgetWrappedElement()booleanhas(Condition 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.SelenideElementhover()Emulate "mouseOver" event.SelenideElementhover(HoverOptions options)Emulate "mouseOver" event.java.lang.StringinnerHtml()Get the HTML code of the element with children.java.lang.StringinnerText()Get the text code of the element with children.booleanis(Condition 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.booleanisDisplayed()Check if this element exists and visible.booleanisImage()Check if image is properly loaded.SelenideElementlastChild()Get last child element of this element For example, $("tr").lastChild(); could give the last "td".java.lang.Stringname()Get the "name" attribute of the elementSelenideElementparent()Get parent element of this element (lazy evaluation) For example, $("td").parent() could give some "tr".SelenideElementpreceding(int index)Get the preceding sibling element of this element For example, $("td").preceding(0) will give the first preceding sibling element of "td"SelenideElementpressEnter()Press ENTER.SelenideElementpressEscape()Press ESCAPE.SelenideElementpressTab()Press TAB.java.lang.Stringpseudo(java.lang.String pseudoElementName)Get content of the pseudo-elementjava.lang.Stringpseudo(java.lang.String pseudoElementName, java.lang.String propertyName)Get the property value of the pseudo-elementjava.io.Filescreenshot()Take screenshot of this elementjava.awt.image.BufferedImagescreenshotAsImage()Take screenshot of this elementSelenideElementscrollIntoView(boolean alignToTop)Ask browser to scrolls the element on which it's called into the visible area of the browser window.SelenideElementscrollIntoView(java.lang.String scrollIntoViewOptions)Ask browser to scrolls the element on which it's called into the visible area of the browser window.SelenideElementscrollTo()Ask browser to scroll to this elementvoidselectOption(int... index)Select an option from dropdown list (by index)voidselectOption(java.lang.String... text)Select an option from dropdown list (by text)voidselectOptionByValue(java.lang.String... value)Select an option from dropdown list (by value)voidselectOptionContainingText(java.lang.String text)Select an option from dropdown list that contains given textSelenideElementselectRadio(java.lang.String value)Select radio buttonSelenideElementsetSelected(boolean selected)Set checkbox state to CHECKED or UNCHECKED.SelenideElementsetValue(java.lang.String text)Implementation details:SelenideElementshould(Condition... condition)Checks that given element meets all of given conditions.SelenideElementshould(Condition condition, java.time.Duration timeout)Wait until given element meets given condition (with given timeout)SelenideElementshouldBe(Condition... condition)Synonym forshould(com.codeborne.selenide.Condition...).SelenideElementshouldBe(Condition condition, java.time.Duration timeout)Wait until given element meets given condition (with given timeout)SelenideElementshouldHave(Condition... condition)Synonym forshould(com.codeborne.selenide.Condition...).SelenideElementshouldHave(Condition condition, java.time.Duration timeout)Wait until given element meets given condition (with given timeout)SelenideElementshouldNot(Condition... condition)Checks that given element does not meet given conditions.SelenideElementshouldNot(Condition condition, java.time.Duration timeout)Wait until given element meets given condition (with given timeout)SelenideElementshouldNotBe(Condition... condition)Synonym forshouldNot(com.codeborne.selenide.Condition...).SelenideElementshouldNotBe(Condition condition, java.time.Duration timeout)Wait until given element does NOT meet given condition (with given timeout)SelenideElementshouldNotHave(Condition... condition)Synonym forshouldNot(com.codeborne.selenide.Condition...).SelenideElementshouldNotHave(Condition condition, java.time.Duration timeout)Wait until given element does NOT meet given condition (with given timeout)SelenideElementsibling(int index)Get the following sibling element of this element For example, $("td").sibling(0) will give the first following sibling element of "td"java.lang.Stringtext()Short form ofgetText()java.lang.StringtoString()Displays WebElement in human-readable format.org.openqa.selenium.WebElementtoWebElement()java.io.FileuploadFile(java.io.File... file)Upload file into file upload field.java.io.FileuploadFromClasspath(java.lang.String... fileName)Upload file into file upload field.java.lang.Stringval()Get the "value" attribute of the element Same asgetValue()SelenideElementval(java.lang.String text)Same assetValue(java.lang.String)SelenideElementwaitUntil(Condition condition, long timeoutMilliseconds)Deprecated.SelenideElementwaitUntil(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)Deprecated.SelenideElementwaitWhile(Condition condition, long timeoutMilliseconds)Deprecated.SelenideElementwaitWhile(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)Deprecated.
-
-
-
Method Detail
-
setValue
@Nonnull @CanIgnoreReturnValue SelenideElement setValue(@Nullable java.lang.String text)
Implementation details:If Configuration.versatileSetValue is true, can work as 'selectOptionByValue', 'selectRadio'
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:
SetValue
-
val
@Nonnull @CanIgnoreReturnValue SelenideElement val(@Nullable java.lang.String text)
Same assetValue(java.lang.String)- See Also:
Val
-
append
@Nonnull @CanIgnoreReturnValue SelenideElement append(java.lang.String text)
Append given text to the text field and trigger "change" event.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:
Append
-
pressEnter
@Nonnull @CanIgnoreReturnValue SelenideElement pressEnter()
Press ENTER. Useful for input field and textareas:$("query").val("Aikido techniques").pressEnter();Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.ENTER)
- See Also:
PressEnter
-
pressTab
@Nonnull @CanIgnoreReturnValue SelenideElement pressTab()
Press TAB. Useful for input field and textareas:$("#to").val("stiven@seagal.com").pressTab();Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.TAB)
- See Also:
PressTab
-
pressEscape
@Nonnull @CanIgnoreReturnValue SelenideElement 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:
PressEscape
-
getText
@CheckReturnValue @Nonnull java.lang.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:
getTextin interfaceorg.openqa.selenium.WebElement- Returns:
- The innerText of this element
- See Also:
GetText, NOT RECOMMENDED
-
getAlias
@CheckReturnValue @Nullable java.lang.String getAlias()
Element alias, which can be set withas(String text)- Returns:
- Alias of this element or null, if element alias is not set
- Since:
- 5.20.0
- See Also:
GetAlias
-
text
@CheckReturnValue @Nonnull java.lang.String text()
Short form ofgetText()- See Also:
WebElement.getText(),GetText, NOT RECOMMENDED
-
getOwnText
@CheckReturnValue @Nonnull java.lang.String getOwnText()
Get the text of the element WITHOUT children.- See Also:
GetOwnText, NOT RECOMMENDED
-
innerText
@CheckReturnValue @Nonnull java.lang.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") or getAttribute("innerText") depending on browser.
- See Also:
GetInnerText, NOT RECOMMENDED
-
innerHtml
@CheckReturnValue @Nonnull java.lang.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:
GetInnerHtml, NOT RECOMMENDED
-
attr
@CheckReturnValue @Nullable java.lang.String attr(java.lang.String attributeName)
Get the attribute of the element. Synonym forgetAttribute(String)- Returns:
- null if attribute is missing
- See Also:
GetAttribute, NOT RECOMMENDED
-
name
@CheckReturnValue @Nullable java.lang.String name()
Get the "name" attribute of the element- Returns:
- attribute "name" value or null if attribute is missing
- See Also:
GetName, NOT RECOMMENDED
-
val
@CheckReturnValue @Nullable java.lang.String val()
Get the "value" attribute of the element Same asgetValue()- Returns:
- attribute "value" value or null if attribute is missing
- See Also:
Val, NOT RECOMMENDED
-
getValue
@CheckReturnValue @Nullable java.lang.String getValue()
Get the "value" attribute of the element- Returns:
- attribute "value" value or null if attribute is missing
- Since:
- 3.1
- See Also:
GetValue, NOT RECOMMENDED
-
pseudo
@CheckReturnValue @Nonnull java.lang.String pseudo(java.lang.String pseudoElementName, java.lang.String propertyName)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:
GetPseudoValue, NOT RECOMMENDED
-
pseudo
@CheckReturnValue @Nonnull java.lang.String pseudo(java.lang.String pseudoElementName)
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:
GetPseudoValue, NOT RECOMMENDED
-
selectRadio
@Nonnull @CanIgnoreReturnValue SelenideElement selectRadio(java.lang.String value)
Select radio button- Parameters:
value- value of radio button to select- Returns:
- selected "input type=radio" element
- See Also:
SelectRadio
-
data
@CheckReturnValue @Nullable java.lang.String data(java.lang.String dataAttributeName)
Get value of attribute "data-dataAttributeName"- See Also:
GetDataAttribute, NOT RECOMMENDED
-
getAttribute
@Nullable @CheckReturnValue java.lang.String getAttribute(java.lang.String name)
- Specified by:
getAttributein interfaceorg.openqa.selenium.WebElement- See Also:
- NOT RECOMMENDED
-
getCssValue
@Nonnull @CheckReturnValue java.lang.String getCssValue(java.lang.String propertyName)
- Specified by:
getCssValuein interfaceorg.openqa.selenium.WebElement- See Also:
- NOT RECOMMENDED
-
exists
@CheckReturnValue 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:
Exists, NOT RECOMMENDED
-
isDisplayed
@CheckReturnValue boolean isDisplayed()
Check if this element exists and visible.- Specified by:
isDisplayedin interfaceorg.openqa.selenium.WebElement- Returns:
- false if element does not exists, is invisible, browser is closed or any WebDriver exception happened.
- See Also:
- NOT RECOMMENDED
-
is
@CheckReturnValue boolean is(Condition 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.
-
has
@CheckReturnValue boolean has(Condition 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.
-
setSelected
@Nonnull @CanIgnoreReturnValue SelenideElement setSelected(boolean selected)
Set checkbox state to CHECKED or UNCHECKED.- Parameters:
selected- true for checked and false for unchecked- See Also:
SetSelected
-
should
@Nonnull @CanIgnoreReturnValue SelenideElement should(Condition... condition)
Checks that given element meets all of 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.timeoutFor example:
$("#errorMessage").should(appear);- Returns:
- Given element, useful for chaining:
$("#errorMessage").should(appear).shouldBe(enabled); - See Also:
Config.timeout(),Should
-
should
@Nonnull @CanIgnoreReturnValue SelenideElement should(Condition condition, java.time.Duration timeout)
Wait until given element meets given condition (with given timeout)
-
shouldHave
@Nonnull @CanIgnoreReturnValue SelenideElement shouldHave(Condition... condition)
Synonym for
should(com.codeborne.selenide.Condition...). Useful for better readability.For example:
$("#errorMessage").shouldHave(text("Hello"), text("World"));
-
shouldHave
@Nonnull @CanIgnoreReturnValue SelenideElement shouldHave(Condition condition, java.time.Duration timeout)
Wait until given element meets given condition (with given timeout)
-
shouldBe
@Nonnull @CanIgnoreReturnValue SelenideElement shouldBe(Condition... condition)
Synonym for
should(com.codeborne.selenide.Condition...). Useful for better readability.For example:
$("#errorMessage").shouldBe(visible, enabled);
-
shouldBe
@Nonnull @CanIgnoreReturnValue SelenideElement shouldBe(Condition condition, java.time.Duration timeout)
Wait until given element meets given condition (with given timeout)
-
shouldNot
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNot(Condition... condition)
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.timeoutFor example:
$("#errorMessage").should(exist);- See Also:
Config.timeout(),ShouldNot
-
shouldNot
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNot(Condition condition, java.time.Duration timeout)
Wait until given element meets given condition (with given timeout)
-
shouldNotHave
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNotHave(Condition... condition)
Synonym for
shouldNot(com.codeborne.selenide.Condition...). Useful for better readability.For example:
$("#errorMessage").shouldNotHave(text("Exception"), text("Error"));
-
shouldNotHave
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNotHave(Condition condition, java.time.Duration timeout)
Wait until given element does NOT meet given condition (with given timeout)
-
shouldNotBe
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNotBe(Condition... condition)
Synonym for
shouldNot(com.codeborne.selenide.Condition...). Useful for better readability.For example:
$("#errorMessage").shouldNotBe(visible, enabled);
-
shouldNotBe
@Nonnull @CanIgnoreReturnValue SelenideElement shouldNotBe(Condition condition, java.time.Duration timeout)
Wait until given element does NOT meet given condition (with given timeout)
-
waitUntil
@Nonnull @CanIgnoreReturnValue @Deprecated SelenideElement waitUntil(Condition condition, long timeoutMilliseconds)
Deprecated.Wait until given element meets given conditions.
IMPORTANT: in most cases you don't need this method because all should- methods wait too. You need to use #waitUntil or #waitWhile methods only if you need another timeout.
- Parameters:
condition- e.g. enabled, visible, text() and so ontimeoutMilliseconds- timeout in milliseconds.- See Also:
WaitUntil
-
waitUntil
@Nonnull @CanIgnoreReturnValue @Deprecated SelenideElement waitUntil(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)
Deprecated.Wait until given element meets given conditions.
IMPORTANT: in most cases you don't need this method because all should- methods wait too. You need to use #waitUntil or #waitWhile methods only if you need another timeout.
- Parameters:
condition- e.g. enabled, visible, text() and so ontimeoutMilliseconds- timeout in milliseconds.pollingIntervalMilliseconds- interval in milliseconds, when checking condition- See Also:
WaitUntil
-
waitWhile
@Nonnull @CanIgnoreReturnValue @Deprecated SelenideElement waitWhile(Condition condition, long timeoutMilliseconds)
Deprecated.Wait until given element does not meet given conditions.
IMPORTANT: in most cases you don't need this method because all shouldNot- methods wait too. You need to use #waitUntil or #waitWhile methods only if you need another timeout.
- Parameters:
condition- e.g. enabled, visible, text() and so ontimeoutMilliseconds- timeout in milliseconds.- See Also:
WaitWhile
-
waitWhile
@Nonnull @CanIgnoreReturnValue @Deprecated SelenideElement waitWhile(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)
Deprecated.Wait until given element does not meet given conditions.
IMPORTANT: in most cases you don't need this method because all shouldNot- methods wait too. You need to use #waitUntil or #waitWhile methods only if you need another timeout.
- Parameters:
condition- e.g. enabled, visible, text() and so ontimeoutMilliseconds- timeout in milliseconds.pollingIntervalMilliseconds- interval in milliseconds, when checking condition- See Also:
WaitWhile
-
toString
@CheckReturnValue @Nonnull java.lang.String toString()
Displays WebElement in human-readable format. Useful for logging and debugging. Not recommended to use for test verifications.- Overrides:
toStringin classjava.lang.Object- Returns:
- e.g. Order has been confirmed
- See Also:
ToString
-
as
@CheckReturnValue @Nonnull SelenideElement as(java.lang.String alias)
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
- Since:
- 5.17.0
-
parent
@CheckReturnValue @Nonnull SelenideElement parent()
Get parent element of this element (lazy evaluation) For example, $("td").parent() could give some "tr".- Returns:
- Parent element
- See Also:
GetParent, Lazy loading
-
sibling
@CheckReturnValue @Nonnull SelenideElement 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"- Parameters:
index- the index of sibling element- Returns:
- Sibling element by index
- See Also:
GetSibling, Lazy loading
-
preceding
@CheckReturnValue @Nonnull SelenideElement 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"- Parameters:
index- the index of sibling element- Returns:
- Sibling element by index
- See Also:
GetPreceding, Lazy loading
-
lastChild
@CheckReturnValue @Nonnull SelenideElement lastChild()
Get last child element of this element For example, $("tr").lastChild(); could give the last "td".- See Also:
- Lazy loading
-
closest
@CheckReturnValue @Nonnull SelenideElement closest(java.lang.String tagOrClass)
Locates closes ancestor element matching given criteria For example, $("td").closest("table") could give some "table".- Parameters:
tagOrClass- Either HTML tag or CSS class. E.g. "form" or ".active".- Returns:
- Matching ancestor element
- See Also:
GetClosest, Lazy loading
-
find
@CheckReturnValue @Nonnull SelenideElement find(java.lang.String cssSelector)
Locates the first matching element inside given element
Short form of
webElement.findElement(By.cssSelector(cssSelector))- See Also:
Find, Lazy loading
-
find
@CheckReturnValue @Nonnull SelenideElement find(java.lang.String cssSelector, int index)
Locates the Nth matching element inside given element
- See Also:
Find, Lazy loading
-
find
@CheckReturnValue SelenideElement find(org.openqa.selenium.By selector)
Same asfind(String)- See Also:
Find, Lazy loading
-
find
@CheckReturnValue @Nonnull SelenideElement find(org.openqa.selenium.By selector, int index)
Same asfind(String, int)- See Also:
Find, Lazy loading
-
$
@CheckReturnValue @Nonnull SelenideElement $(java.lang.String cssSelector)
Same asfind(String)- See Also:
Find, Lazy loading
-
$
@CheckReturnValue @Nonnull SelenideElement $(java.lang.String cssSelector, int index)
Same asfind(String, int)- See Also:
Find, Lazy loading
-
$
@CheckReturnValue @Nonnull SelenideElement $(org.openqa.selenium.By selector)
Same asfind(String)- See Also:
Find, Lazy loading
-
$
@CheckReturnValue @Nonnull SelenideElement $(org.openqa.selenium.By selector, int index)
Same asfind(String, int)- See Also:
Find, Lazy loading
-
$x
@CheckReturnValue @Nonnull SelenideElement $x(java.lang.String xpath)
Locates the first matching element inside given element using xpath locator
Short form of
webElement.findElement(By.xpath(xpathLocator))- See Also:
FindByXpath, Lazy loading
-
$x
@CheckReturnValue @Nonnull SelenideElement $x(java.lang.String xpath, int index)
Locates the Nth matching element inside given element using xpath locator
- See Also:
FindByXpath, Lazy loading
-
findAll
@CheckReturnValue @Nonnull ElementsCollection findAll(java.lang.String cssSelector)
Short form of
webDriver.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, Lazy loading
-
findAll
@CheckReturnValue @Nonnull ElementsCollection findAll(org.openqa.selenium.By selector)
Short form of
webDriver.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:
FindAll, Lazy loading
-
$$
@CheckReturnValue @Nonnull ElementsCollection $$(java.lang.String cssSelector)
Same asfindAll(String)- See Also:
- Lazy loading
-
$$
@CheckReturnValue @Nonnull ElementsCollection $$(org.openqa.selenium.By selector)
Same asfindAll(By)
-
$$x
@CheckReturnValue @Nonnull ElementsCollection $$x(java.lang.String xpath)
Short form of
webDriver.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:
FindAllByXpath, Lazy loading
-
uploadFromClasspath
@Nonnull @CanIgnoreReturnValue java.io.File uploadFromClasspath(java.lang.String... fileName)
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.
- 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:
java.lang.IllegalArgumentException- if any of the files is not found- See Also:
UploadFileFromClasspath
-
uploadFile
@Nonnull @CanIgnoreReturnValue java.io.File uploadFile(java.io.File... file)
Upload file into file upload field.
Multiple file upload is also supported. Just pass as many files as you wish.
- Parameters:
file- file object(s)- Returns:
- the object of the first file uploaded
- Throws:
java.lang.IllegalArgumentException- if any of the files is not found, or other errors- See Also:
UploadFile
-
selectOption
void selectOption(int... index)
Select an option from dropdown list (by index)- Parameters:
index- 0..N (0 means first option)- See Also:
SelectOptionByTextOrIndex
-
selectOption
void selectOption(java.lang.String... text)
Select an option from dropdown list (by text)- Parameters:
text- visible text of option- See Also:
SelectOptionByTextOrIndex
-
selectOptionContainingText
void selectOptionContainingText(java.lang.String text)
Select an option from dropdown list that contains given text- Parameters:
text- substring of visible text of option- See Also:
SelectOptionContainingText
-
selectOptionByValue
void selectOptionByValue(java.lang.String... value)
Select an option from dropdown list (by value)- Parameters:
value- "value" attribute of option- See Also:
SelectOptionByValue
-
getSelectedOption
@CheckReturnValue @Nonnull SelenideElement getSelectedOption() throws org.openqa.selenium.NoSuchElementException
Find (first) selected option from this select field- Returns:
- WebElement for selected <option> element
- Throws:
org.openqa.selenium.NoSuchElementException- if no options are selected- See Also:
GetSelectedOption, NOT RECOMMENDED
-
getSelectedOptions
@CheckReturnValue @Nonnull ElementsCollection getSelectedOptions()
Find all selected options from this select field- Returns:
- ElementsCollection for selected <option> elements (empty list if no options are selected)
- See Also:
GetSelectedOptions, NOT RECOMMENDED
-
getSelectedValue
@CheckReturnValue @Nullable java.lang.String getSelectedValue()
Get value of selected option in select field- Returns:
- null if the selected option doesn't have "value" attribute
- See Also:
GetSelectedValue, NOT RECOMMENDED
-
getSelectedText
@CheckReturnValue @Nonnull java.lang.String getSelectedText()
Get text of selected option in select field- See Also:
GetSelectedText, NOT RECOMMENDED
-
scrollTo
@Nonnull @CanIgnoreReturnValue SelenideElement scrollTo()
Ask browser to scroll to this element- See Also:
ScrollTo
-
scrollIntoView
@Nonnull @CanIgnoreReturnValue SelenideElement scrollIntoView(boolean alignToTop)
Ask browser to scrolls 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, Web API reference
-
scrollIntoView
@Nonnull @CanIgnoreReturnValue SelenideElement scrollIntoView(java.lang.String scrollIntoViewOptions)
Ask browser to scrolls 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 2. center (default) 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:
ScrollIntoView, Web API reference
-
download
@CheckReturnValue @Nonnull java.io.File download() throws java.io.FileNotFoundExceptionDownload file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }.- Throws:
java.lang.RuntimeException- if 50x status code was returned from serverjava.io.FileNotFoundException- if 40x status code was returned from server- See Also:
FileDownloadMode,DownloadFile
-
download
@CheckReturnValue @Nonnull java.io.File download(long timeout) throws java.io.FileNotFoundExceptionDownload file by clicking this element. Algorithm depends on@{@link Config#fileDownload() }.- Parameters:
timeout- download operations timeout.- Throws:
java.lang.RuntimeException- if 50x status code was returned from serverjava.io.FileNotFoundException- if 40x status code was returned from server- See Also:
DownloadFile
-
download
@CheckReturnValue @Nonnull java.io.File download(FileFilter fileFilter) throws java.io.FileNotFoundException
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:
java.lang.RuntimeException- if 50x status code was returned from serverjava.io.FileNotFoundException- if 40x status code was returned from server, or the downloaded file didn't match given filter.- See Also:
FileFilters,DownloadFile
-
download
@CheckReturnValue @Nonnull java.io.File download(long timeout, FileFilter fileFilter) throws java.io.FileNotFoundExceptionDownload 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:
java.lang.RuntimeException- if 50x status code was returned from serverjava.io.FileNotFoundException- if 40x status code was returned from server, or the downloaded file didn't match given filter.- See Also:
FileFilters,DownloadFile
-
download
@CheckReturnValue @Nonnull java.io.File download(DownloadOptions options) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
getSearchCriteria
@CheckReturnValue @Nonnull java.lang.String getSearchCriteria()
Return criteria by which this element is located- Returns:
- e.g. "#multirowTable.findBy(text 'INVALID-TEXT')/valid-selector"
- See Also:
GetSearchCriteria
-
toWebElement
@CheckReturnValue @Nonnull org.openqa.selenium.WebElement toWebElement()
- Returns:
- the original Selenium
WebElementwrapped by this object - Throws:
org.openqa.selenium.NoSuchElementException- if element does not exist (without waiting for the element)- See Also:
ToWebElement
-
getWrappedElement
@CheckReturnValue @Nonnull org.openqa.selenium.WebElement getWrappedElement()
- Specified by:
getWrappedElementin interfaceorg.openqa.selenium.WrapsElement- Returns:
- Underlying
WebElement - Throws:
ElementNotFound- if element does not exist (after waiting for N seconds)- See Also:
GetWrappedElement
-
click
void click(ClickOptions clickOption)
Click the element usingClickOptions:$("#username").click(ClickOptions.usingJavaScript())You can specify a relative offset from the center of the element inside ClickOptions: e.g.
$("#username").click(usingJavaScript().offset(123, 222))- See Also:
Click
-
click
void click()
Click the elementBy default it uses default Selenium method click.
But it uses JavaScript method to click if
com.codeborne.selenide.Configuration#clickViaJsis defined. It may be helpful for testing in Internet Explorer where native click doesn't always work correctly.- Specified by:
clickin interfaceorg.openqa.selenium.WebElement- See Also:
Click
-
click
@Deprecated void click(int offsetX, int offsetY)Deprecated.useclick(ClickOptions)with offsetsClick the element with a relative offset from the center of the element
-
contextClick
@Nonnull @CanIgnoreReturnValue SelenideElement contextClick()
Click with right mouse button on this element- Returns:
- this element
- See Also:
ContextClick
-
doubleClick
@Nonnull @CanIgnoreReturnValue SelenideElement doubleClick()
Double click the element- Returns:
- this element
- See Also:
DoubleClick
-
hover
@Nonnull @CanIgnoreReturnValue SelenideElement hover()
Emulate "mouseOver" event. In other words, move mouse cursor over this element (without clicking it).- Returns:
- this element
- See Also:
Hover
-
hover
@Nonnull @CanIgnoreReturnValue SelenideElement hover(HoverOptions options)
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:
Hover
-
dragAndDropTo
@Nonnull @CanIgnoreReturnValue SelenideElement dragAndDropTo(java.lang.String targetCssSelector)
Drag and drop this element to the targetBefore dropping, waits until target element gets visible.
- Parameters:
targetCssSelector- CSS selector defining target element- Returns:
- this element
- See Also:
DragAndDropTo
-
dragAndDropTo
@Nonnull @CanIgnoreReturnValue SelenideElement dragAndDropTo(org.openqa.selenium.WebElement target)
Drag and drop this element to the targetBefore dropping, waits until target element gets visible.
- Parameters:
target- target element- Returns:
- this element
- See Also:
DragAndDropTo
-
dragAndDropTo
@Nonnull @CanIgnoreReturnValue SelenideElement dragAndDropTo(java.lang.String targetCssSelector, DragAndDropOptions options)
Drag and drop this element to the target via JS script see resources/drag_and_drop_scriptBefore dropping, waits until target element gets visible.
- Parameters:
targetCssSelector- target css selectoroptions- drag and drop options to define which way it will be executed- Returns:
- this element
- See Also:
DragAndDropTo
-
execute
<ReturnType> ReturnType execute(Command<ReturnType> command)
Execute custom implemented command
-
isImage
boolean isImage()
Check if image is properly loaded.- Throws:
java.lang.IllegalArgumentException- if argument is not an "img" element- Since:
- 2.13
- See Also:
IsImage, NOT RECOMMENDED
-
screenshot
@CheckReturnValue @Nullable java.io.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:
TakeScreenshot
-
screenshotAsImage
@CheckReturnValue @Nullable java.awt.image.BufferedImage screenshotAsImage()
Take screenshot of this element- Returns:
- buffered image with screenshot
- See Also:
TakeScreenshotAsImage
-
-