public interface SelenideElement
extends org.openqa.selenium.WebElement, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.internal.WrapsDriver, org.openqa.selenium.internal.WrapsElement, org.openqa.selenium.internal.Locatable
WebElement
with additional methods like
shouldBe(Condition...)
and shouldHave(Condition...)
Modifier and Type | Method and Description |
---|---|
SelenideElement |
$(org.openqa.selenium.By selector)
ATTENTION! This method doesn't start any search yet!
Same as
find(String) |
SelenideElement |
$(org.openqa.selenium.By selector,
int index)
ATTENTION! This method doesn't start any search yet!
Same as
find(String, int) |
SelenideElement |
$(java.lang.String cssSelector)
ATTENTION! This method doesn't start any search yet!
Same as
find(String) |
SelenideElement |
$(java.lang.String cssSelector,
int index)
ATTENTION! This method doesn't start any search yet!
Same as
find(String, int) |
ElementsCollection |
$$(org.openqa.selenium.By selector)
Same as
findAll(By) |
ElementsCollection |
$$(java.lang.String cssSelector)
ATTENTION! This method doesn't start any search yet!
Same as
findAll(String) |
ElementsCollection |
$$x(java.lang.String xpath)
Short form of
webDriver.findElements(thisElement, By.xpath(xpath)) |
SelenideElement |
$x(java.lang.String xpath)
Locates the first matching element inside given element using xpath locator
|
SelenideElement |
$x(java.lang.String xpath,
int index)
Locates the Nth matching element inside given element using xpath locator
|
SelenideElement |
append(java.lang.String text)
Append given test to the text field and trigger "change" event.
|
java.lang.String |
attr(java.lang.String attributeName)
Get the attribute of the element.
|
void |
click()
Click the element
|
SelenideElement |
closest(java.lang.String tagOrClass)
Locates closes ancestor element matching given criteria
ATTENTION! This method doesn't start any search yet!
For example, $("td").closest("table") could give some "table".
|
SelenideElement |
contextClick()
Click with right mouse button on this element
|
java.lang.String |
data(java.lang.String dataAttributeName)
Get value of attribute "data-dataAttributeName"
|
SelenideElement |
doubleClick()
Double click the element
|
java.io.File |
download()
Download file linked by "href" attribute of this element
|
SelenideElement |
dragAndDropTo(java.lang.String targetCssSelector)
Drag and drop this element to the target
Before dropping, waits until target element gets visible.
|
SelenideElement |
dragAndDropTo(org.openqa.selenium.WebElement target)
Drag and drop this element to the target
Before dropping, waits until target element gets visible.
|
boolean |
exists()
Checks if element exists true on the current page.
|
SelenideElement |
find(org.openqa.selenium.By selector)
ATTENTION! This method doesn't start any search yet!
Same as
find(String) |
SelenideElement |
find(org.openqa.selenium.By selector,
int index)
ATTENTION! This method doesn't start any search yet!
Same as
find(String, int) |
SelenideElement |
find(java.lang.String cssSelector)
Locates the first matching element inside given element
|
SelenideElement |
find(java.lang.String cssSelector,
int index)
Locates the Nth matching element inside given element
|
ElementsCollection |
findAll(org.openqa.selenium.By selector)
Short form of
webDriver.findElements(thisElement, selector) |
ElementsCollection |
findAll(java.lang.String cssSelector)
Short form of
webDriver.findElements(thisElement, By.cssSelector(cssSelector)) |
void |
followLink()
Actual for <a href> elements.
|
SelenideElement |
getSelectedOption()
Find (first) selected option from this select field
|
ElementsCollection |
getSelectedOptions()
Find all selected options from this select field
|
java.lang.String |
getSelectedText()
Get text of selected option in select field
|
java.lang.String |
getSelectedValue()
Get value of selected option in select field
|
java.lang.String |
getText()
Get the visible text of this element, including sub-elements without leading/trailing whitespace.
|
java.lang.String |
getValue()
Get the "value" attribute of the element
|
org.openqa.selenium.WebElement |
getWrappedElement() |
boolean |
has(Condition condition)
Return true iff element matches given condition
|
SelenideElement |
hover()
Emulate "mouseOver" event.
|
java.lang.String |
innerHtml()
Get the HTML code of the element with children.
|
java.lang.String |
innerText()
Get the text code of the element with children.
|
boolean |
is(Condition condition)
Return true iff element matches given condition
|
boolean |
isDisplayed()
Check if this element exists and visible.
|
boolean |
isImage()
Check if image is properly loaded.
|
java.lang.String |
name()
Get the "name" attribute of the element
|
SelenideElement |
parent()
Get parent element of this element
ATTENTION! This method doesn't start any search yet!
For example, $("td").parent() could give some "tr".
|
SelenideElement |
pressEnter()
Press ENTER.
|
SelenideElement |
pressEscape()
Press ESCAPE.
|
SelenideElement |
pressTab()
Press TAB.
|
java.io.File |
screenshot()
Take screenshot of this element
|
java.awt.image.BufferedImage |
screenshotAsImage()
Take screenshot of this element
|
SelenideElement |
scrollTo()
Ask browser to scroll to this element
|
void |
selectOption(int... index)
Select an option from dropdown list (by index)
|
void |
selectOption(java.lang.String... text)
Select an option from dropdown list (by text)
|
void |
selectOptionByValue(java.lang.String... value)
Select an option from dropdown list (by value)
|
void |
selectOptionContainingText(java.lang.String text)
Select an option from dropdown list that contains given text
|
SelenideElement |
selectRadio(java.lang.String value)
Select radio button
|
SelenideElement |
setSelected(boolean selected)
Set checkbox state to CHECKED or UNCHECKED.
|
SelenideElement |
setValue(java.lang.String text)
Implementation details:
|
SelenideElement |
should(Condition... condition)
Checks that given element meets all of given conditions.
|
SelenideElement |
shouldBe(Condition... condition)
Synonym for #should.
|
SelenideElement |
shouldHave(Condition... condition)
Synonym for #should.
|
SelenideElement |
shouldNot(Condition... condition)
Checks that given element does not meet given conditions.
|
SelenideElement |
shouldNotBe(Condition... condition)
Synonym for #shouldNot.
|
SelenideElement |
shouldNotHave(Condition... condition)
Synonym for #shouldNot.
|
java.lang.String |
text()
Short form of getText()
|
java.lang.String |
toString()
Displays WebElement in human-readable format.
|
org.openqa.selenium.WebElement |
toWebElement() |
java.io.File |
uploadFile(java.io.File... file)
Upload file into file upload field.
|
java.io.File |
uploadFromClasspath(java.lang.String... fileName)
Upload file into file upload field.
|
java.lang.String |
val()
Get the "value" attribute of the element
Same as #getValue()
|
SelenideElement |
val(java.lang.String text)
Same as #setValue(java.lang.String)
|
SelenideElement |
waitUntil(Condition condition,
long timeoutMilliseconds)
Wait until given element meets given conditions.
|
SelenideElement |
waitUntil(Condition condition,
long timeoutMilliseconds,
long pollingIntervalMilliseconds)
Wait until given element meets given conditions.
|
SelenideElement |
waitWhile(Condition condition,
long timeoutMilliseconds)
Wait until given element does not meet given conditions.
|
SelenideElement |
waitWhile(Condition condition,
long timeoutMilliseconds,
long pollingIntervalMilliseconds)
Wait until given element does not meet given conditions.
|
clear, findElement, findElements, getAttribute, getCssValue, getLocation, getRect, getSize, getTagName, isEnabled, isSelected, sendKeys, submit
findElementByLinkText, findElementByPartialLinkText, findElementsByLinkText, findElementsByPartialLinkText
findElementById, findElementsById
findElementByName, findElementsByName
findElementByTagName, findElementsByTagName
findElementByClassName, findElementsByClassName
findElementByCssSelector, findElementsByCssSelector
void followLink()
Actual for <a href> elements. Navigates browser by clicking this link.
In some situations just clicking is not enough: $.click() doesn't take effect for <a href>. In these cases use #followLink that actually navigates browser to @href value.
FollowLink
SelenideElement setValue(java.lang.String text)
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
text
- Any text to enter into the text field or set by value for select/radio.SetValue
SelenideElement val(java.lang.String text)
Val
SelenideElement append(java.lang.String text)
Append given test to the text field and trigger "change" event.
Implementation details: This is the same as
1. WebElement.sendKeys(text) 2. Trigger change event
text
- Any text to append into the text field.Append
SelenideElement pressEnter()
$("query").val("Aikido techniques").pressEnter();Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.ENTER)
PressEnter
SelenideElement pressTab()
$("#to").val("[email protected]").pressTab();Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.TAB)
PressTab
SelenideElement pressEscape()
$(".edit").click().pressEscape();Implementation details: Check that element is displayed and execute
WebElement.sendKeys(Keys.ESCAPE)
PressEscape
java.lang.String getText()
getText
in interface org.openqa.selenium.WebElement
GetText
java.lang.String text()
WebElement.getText()
,
GetText
java.lang.String innerText()
GetInnerText
java.lang.String innerHtml()
GetInnerHtml
java.lang.String attr(java.lang.String attributeName)
GetAttribute
java.lang.String name()
GetName
java.lang.String val()
Val
java.lang.String getValue()
GetValue
SelenideElement selectRadio(java.lang.String value)
value
- value of radio button to selectSelectRadio
java.lang.String data(java.lang.String dataAttributeName)
GetDataAttribute
boolean exists()
Exists
boolean isDisplayed()
isDisplayed
in interface org.openqa.selenium.WebElement
IsDisplayed
boolean is(Condition condition)
Matches
boolean has(Condition condition)
Matches
SelenideElement setSelected(boolean selected)
selected
- true for checked and false for uncheckedSetSelected
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#timeout
For example: $("#errorMessage").should(appear);
$("#errorMessage").should(appear).shouldBe(enabled);
Configuration.timeout
,
Should
SelenideElement shouldHave(Condition... condition)
Synonym for #should. Useful for better readability.
For example: $("#errorMessage").shouldHave(text("Hello"), text("World"));
SelenideElement shouldBe(Condition... condition)
Synonym for #should. Useful for better readability.
For example: $("#errorMessage").shouldBe(visible, enabled);
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#timeout
For example: $("#errorMessage").should(exist);
Configuration.timeout
,
ShouldNot
SelenideElement shouldNotHave(Condition... condition)
Synonym for #shouldNot. Useful for better readability.
For example: $("#errorMessage").shouldNotHave(text("Exception"), text("Error"));
SelenideElement shouldNotBe(Condition... condition)
Synonym for #shouldNot. Useful for better readability.
For example: $("#errorMessage").shouldNotBe(visible, enabled);
SelenideElement waitUntil(Condition condition, long timeoutMilliseconds)
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.
condition
- e.g. enabled, visible, text() and so ontimeoutMilliseconds
- timeout in milliseconds.ShouldBe
SelenideElement waitUntil(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)
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.
condition
- e.g. enabled, visible, text() and so ontimeoutMilliseconds
- timeout in milliseconds.pollingIntervalMilliseconds
- interval in milliseconds, when checking conditionShouldBe
SelenideElement waitWhile(Condition condition, long timeoutMilliseconds)
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.
condition
- e.g. enabled, visible, text() and so ontimeoutMilliseconds
- timeout in milliseconds.ShouldNotBe
SelenideElement waitWhile(Condition condition, long timeoutMilliseconds, long pollingIntervalMilliseconds)
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.
condition
- e.g. enabled, visible, text() and so ontimeoutMilliseconds
- timeout in milliseconds.pollingIntervalMilliseconds
- interval in milliseconds, when checking conditionShouldNotBe
java.lang.String toString()
toString
in class java.lang.Object
ToString
SelenideElement parent()
GetParent
SelenideElement closest(java.lang.String tagOrClass)
tagOrClass
- Either HTML tag or CSS class. E.g. "form" or ".active".GetClosest
SelenideElement find(java.lang.String cssSelector)
Locates the first matching element inside given element
ATTENTION! This method doesn't start any search yet!Short form of webElement.findElement(By.cssSelector(cssSelector))
Find
SelenideElement find(java.lang.String cssSelector, int index)
Locates the Nth matching element inside given element
ATTENTION! This method doesn't start any search yet!Find
SelenideElement find(org.openqa.selenium.By selector)
find(String)
Find
SelenideElement find(org.openqa.selenium.By selector, int index)
find(String, int)
Find
SelenideElement $(java.lang.String cssSelector)
find(String)
Find
SelenideElement $(java.lang.String cssSelector, int index)
find(String, int)
Find
SelenideElement $(org.openqa.selenium.By selector)
find(String)
Find
SelenideElement $(org.openqa.selenium.By selector, int index)
find(String, int)
Find
SelenideElement $x(java.lang.String xpath)
Locates the first matching element inside given element using xpath locator
ATTENTION! This method doesn't start any search yet!Short form of webElement.findElement(By.xpath(xpathLocator))
FindByXpath
SelenideElement $x(java.lang.String xpath, int index)
Locates the Nth matching element inside given element using xpath locator
ATTENTION! This method doesn't start any search yet!FindByXpath
ElementsCollection findAll(java.lang.String cssSelector)
Short form of webDriver.findElements(thisElement, By.cssSelector(cssSelector))
For example, $("#multirowTable").findAll("tr.active").shouldHave(size(2));
FindAll
ElementsCollection findAll(org.openqa.selenium.By selector)
Short form of webDriver.findElements(thisElement, selector)
For example, $("#multirowTable").findAll(By.className("active")).shouldHave(size(2));
FindAll
ElementsCollection $$(java.lang.String cssSelector)
findAll(String)
ElementsCollection $$(org.openqa.selenium.By selector)
findAll(By)
ElementsCollection $$x(java.lang.String xpath)
Short form of webDriver.findElements(thisElement, By.xpath(xpath))
For example, $("#multirowTable").$$x("./input").shouldHave(size(2));
FindAllByXpath
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.
fileName
- name of the file or the relative path in classpath e.g. "files/1.pfd"java.lang.IllegalArgumentException
- if any of the files is not foundUploadFileFromClasspath
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.
file
- file object(s)java.lang.IllegalArgumentException
- if any of the files is not found, or other errorsUploadFile
void selectOption(int... index)
index
- 0..N (0 means first option)SelectOptionByTextOrIndex
void selectOption(java.lang.String... text)
text
- visible text of optionSelectOptionByTextOrIndex
void selectOptionContainingText(java.lang.String text)
text
- substring of visible text of optionSelectOptionContainingText
void selectOptionByValue(java.lang.String... value)
value
- "value" attribute of optionSelectOptionByValue
SelenideElement getSelectedOption() throws org.openqa.selenium.NoSuchElementException
org.openqa.selenium.NoSuchElementException
- if no options are selectedGetSelectedOption
ElementsCollection getSelectedOptions()
GetSelectedOptions
java.lang.String getSelectedValue()
GetSelectedValue
java.lang.String getSelectedText()
GetSelectedText
SelenideElement scrollTo()
ScrollTo
java.io.File download() throws java.io.FileNotFoundException
java.lang.RuntimeException
- if 50x status code was returned from serverjava.io.FileNotFoundException
- if 40x status code was returned from serverDownloadFile
org.openqa.selenium.WebElement toWebElement()
ToWebElement
org.openqa.selenium.WebElement getWrappedElement()
getWrappedElement
in interface org.openqa.selenium.internal.WrapsElement
WebElement
GetWrappedElement
void click()
By 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.
click
in interface org.openqa.selenium.WebElement
Click
SelenideElement contextClick()
ContextClick
SelenideElement doubleClick()
DoubleClick
SelenideElement hover()
Hover
SelenideElement dragAndDropTo(java.lang.String targetCssSelector)
targetCssSelector
- CSS selector defining target elementDragAndDropTo
SelenideElement dragAndDropTo(org.openqa.selenium.WebElement target)
target
- target elementDragAndDropTo
boolean isImage()
java.lang.IllegalArgumentException
- if argument is not an "img" elementIsImage
java.io.File screenshot()
TakeScreenshot
java.awt.image.BufferedImage screenshotAsImage()
TakeScreenshotAsImage