Package io.karatelabs.driver
Class BaseElement
java.lang.Object
io.karatelabs.driver.BaseElement
- All Implemented Interfaces:
Element,io.karatelabs.js.ObjectLike,io.karatelabs.js.SimpleObject
- Direct Known Subclasses:
MissingElement,W3cElement
Locator-based Element implementation that delegates all operations to a Driver.
This is the default implementation used by all backends (CDP, W3C WebDriver, etc.).
Operations are performed by passing the locator to the Driver, which handles
backend-specific execution (JS eval for CDP, HTTP calls for W3C, etc.).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Driverprotected final booleanprotected final StringFields inherited from interface io.karatelabs.js.SimpleObject
logger, TO_STRING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidGuard run before every operation that needs the element in the page.clear()click()The closest ancestor (or self) matching the given CSS selector.booleanenabled()static BaseElementConstruct an Element whose existence has already been verified by the caller.booleanexists()focus()html()booleanprotected static booleanisPureJsLocator(String locator) A pure-JS locator is a JS expression that evaluates to an element at runtime — produced byclosest(String)and anything else routing throughLocators.wrapInFunctionInvoke(java.lang.String).JS members follow the Java API: every operation is a method (exists(),text(),click()).booleanWhether this element matches the given CSS selector.static BaseElementstatic BaseElementposition()position(boolean relative) retry()retry(int count) retry(int count, int interval) scroll()select(int index) submit()text()toString()value()waitFor()waitForText(String expected) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.karatelabs.js.ObjectLike
getMember, getPrototype, isExtensible, isFrozen, isOwnProperty, isSealed, putMember, removeMember, setExtensible, setFrozen, setSealedMethods inherited from interface io.karatelabs.js.SimpleObject
getMember, jsKeys, jsToString, putMember, removeMember, toMap
-
Field Details
-
driver
-
locator
-
exists
protected final boolean exists
-
-
Constructor Details
-
BaseElement
-
-
Method Details
-
of
-
optional
-
existing
Construct an Element whose existence has already been verified by the caller. Skips the exists() round-trip, which also avoids re-entering the driver at a moment when it may be unable to evaluate JS — e.g. after click() opened a blocking alert/confirm/prompt dialog. -
exists
public boolean exists() -
isPresent
public boolean isPresent() -
getLocator
- Specified by:
getLocatorin interfaceElement
-
text
-
html
-
innerHtml
-
value
-
attribute
-
property
-
enabled
public boolean enabled() -
position
-
position
-
click
-
focus
-
clear
-
input
-
inputFile
-
value
-
select
-
select
-
scroll
-
highlight
-
submit
-
locate
-
locateAll
-
isPureJsLocator
A pure-JS locator is a JS expression that evaluates to an element at runtime — produced byclosest(String)and anything else routing throughLocators.wrapInFunctionInvoke(java.lang.String). Distinguished from XPath (which starts with(//) and from wildcard/CSS. -
closest
Description copied from interface:ElementThe closest ancestor (or self) matching the given CSS selector. Mirrors the nativeElement.closest()DOM API — robust to markup shuffling, preferred over counting parent hops. -
matches
Description copied from interface:ElementWhether this element matches the given CSS selector. Mirrors the nativeElement.matches()DOM API. -
script
-
waitFor
-
waitForText
- Specified by:
waitForTextin interfaceElement
-
waitForEnabled
- Specified by:
waitForEnabledin interfaceElement
-
waitUntil
-
retry
-
retry
-
retry
-
jsGet
JS members follow the Java API: every operation is a method (exists(),text(),click()). The one property ispresent, the v1 idiom foroptional(locator).present— as a callable it would be truthy even for a missing element.- Specified by:
jsGetin interfaceio.karatelabs.js.SimpleObject
-
assertExists
protected void assertExists()Guard run before every operation that needs the element in the page. The snapshot taken at lookup decides;BaseElement.RetryElementwaits instead. -
toString
-