Interface JvmWebDriver
-
- All Implemented Interfaces:
public interface JvmWebDriverJvmWebDriver defines a concise interface to visit and interact with web pages, all actions and behaviors are optimized to mimic real people as closely as possible, such as scrolling, clicking, typing text, dragging and dropping, etc.
JvmWebDriver is programmatically generated from the WebDriver class and is designed to help handle WebDriver tasks in other JVM languages such as java, clojure, scala, and so on, which had difficulty handling kotlin suspend methods.
-
-
Method Summary
Modifier and Type Method Description abstract CompletableFuture<Unit>addInitScriptAsync(String script)Adds a script which would be evaluated in one of the following scenarios: Whenever the page is navigated.
abstract CompletableFuture<Unit>addBlockedURLsAsync(List<String> urls)Blocks URLs from loading. abstract CompletableFuture<Unit>navigateToAsync(String url)Returns the main resource response. abstract CompletableFuture<Unit>navigateToAsync(NavigateEntry entry)Returns the response of the main resource. abstract CompletableFuture<Unit>setTimeoutsAsync(BrowserSettings browserSettings)abstract CompletableFuture<String>currentUrlAsync()Returns a string representing the current URL that the browser is looking at. abstract CompletableFuture<String>pageSourceAsync()Returns the source of the last loaded page. abstract CompletableFuture<Map<String, Object>>mainRequestHeadersAsync()abstract CompletableFuture<List<Map<String, String>>>mainRequestCookiesAsync()abstract CompletableFuture<List<Map<String, String>>>getCookiesAsync()abstract CompletableFuture<Unit>bringToFrontAsync()Brings page to front (activates tab). abstract CompletableFuture<Long>waitForSelectorAsync(String selector)Returns when element specified by selector satisfies {@code state} option. abstract CompletableFuture<Long>waitForSelectorAsync(String selector, Long timeoutMillis)Returns when element specified by selector satisfies {@code state} option. abstract CompletableFuture<Long>waitForSelectorAsync(String selector, Duration timeout)abstract CompletableFuture<Long>waitForNavigationAsync()abstract CompletableFuture<Long>waitForNavigationAsync(Long timeoutMillis)abstract CompletableFuture<Long>waitForNavigationAsync(Duration timeout)abstract CompletableFuture<Boolean>existsAsync(String selector)abstract CompletableFuture<Boolean>isHiddenAsync(String selector)abstract CompletableFuture<Boolean>isVisibleAsync(String selector)abstract CompletableFuture<Boolean>visibleAsync(String selector)abstract CompletableFuture<Boolean>isCheckedAsync(String selector)abstract CompletableFuture<Unit>typeAsync(String selector, String text)CompletableFuture<Unit>clickAsync(String selector)abstract CompletableFuture<Unit>clickAsync(String selector, Integer count)CompletableFuture<Unit>clickMatchesAsync(String selector, String pattern)abstract CompletableFuture<Unit>clickMatchesAsync(String selector, String pattern, Integer count)abstract CompletableFuture<Unit>clickMatchesAsync(String selector, String attrName, String pattern, Integer count)abstract CompletableFuture<String>clickNthAnchorAsync(Integer n, String rootSelector)abstract CompletableFuture<Unit>checkAsync(String selector)abstract CompletableFuture<Unit>uncheckAsync(String selector)abstract CompletableFuture<Unit>scrollToAsync(String selector)abstract CompletableFuture<Unit>scrollDownAsync(Integer count)abstract CompletableFuture<Unit>scrollUpAsync(Integer count)abstract CompletableFuture<Unit>scrollToTopAsync()abstract CompletableFuture<Unit>scrollToBottomAsync()abstract CompletableFuture<Unit>scrollToMiddleAsync(Float ratio)abstract CompletableFuture<Unit>mouseWheelDownAsync(Integer count, Double deltaX, Double deltaY, Long delayMillis)abstract CompletableFuture<Unit>mouseWheelUpAsync(Integer count, Double deltaX, Double deltaY, Long delayMillis)abstract CompletableFuture<Unit>moveMouseToAsync(Double x, Double y)abstract CompletableFuture<Unit>dragAndDropAsync(String selector, Integer deltaX, Integer deltaY)abstract CompletableFuture<String>outerHTMLAsync(String selector)abstract CompletableFuture<String>firstTextAsync(String selector)abstract CompletableFuture<List<String>>allTextsAsync(String selector)abstract CompletableFuture<String>firstAttrAsync(String selector, String attrName)abstract CompletableFuture<List<String>>allAttrsAsync(String selector, String attrName)abstract CompletableFuture<Object>evaluateAsync(String expression)Executes JavaScript in the context of the currently selected frame or window. abstract CompletableFuture<Object>evaluateSilentlyAsync(String expression)Executes JavaScript in the context of the currently selected frame or window. abstract CompletableFuture<String>captureScreenshotAsync(String selector)This method scrolls element into view if needed, and then ake a screenshot of the element. abstract CompletableFuture<String>captureScreenshotAsync(RectD rect)abstract CompletableFuture<PointD>clickablePointAsync(String selector)Calculate the clickable point of an element located by selector. abstract CompletableFuture<RectD>boundingBoxAsync(String selector)Return the bounding box of an element located by selector. abstract CompletableFuture<Connection>newSessionAsync()Create a new Jsoup session with the last page's context, which means, the same headers and cookies. abstract CompletableFuture<NetworkResourceResponse>loadResourceAsync(String url)Load url as a resource without browser rendering, with the last page's context, which means, the same headers and cookies. abstract CompletableFuture<Unit>pauseAsync()Force the page pauses all navigations and PENDING resource fetches. abstract CompletableFuture<Unit>stopAsync()Force the page stop all navigations and RELEASES all resources. abstract CompletableFuture<Unit>terminateAsync()Force the page stop all navigations and RELEASES all resources. -
-
Method Detail
-
addInitScriptAsync
abstract CompletableFuture<Unit> addInitScriptAsync(String script)
Adds a script which would be evaluated in one of the following scenarios:
Whenever the page is navigated.
The script is evaluated after the document was created but before any of its scripts were run. This is useful to amend the JavaScript environment, e.g. to seed Math.random.
- Parameters:
script- Javascript source code to add.
-
addBlockedURLsAsync
abstract CompletableFuture<Unit> addBlockedURLsAsync(List<String> urls)
Blocks URLs from loading.
- Parameters:
urls- URL patterns to block.
-
navigateToAsync
abstract CompletableFuture<Unit> navigateToAsync(String url)
Returns the main resource response. In case of multiple redirects, the navigation will resolve with the first non-redirect response.
- Parameters:
url- URL to navigate page to.
-
navigateToAsync
abstract CompletableFuture<Unit> navigateToAsync(NavigateEntry entry)
Returns the response of the main resource. In case of multiple redirects, the navigation will resolve with the first non-redirect response.
- Parameters:
entry- NavigateEntry to navigate page to.
-
setTimeoutsAsync
abstract CompletableFuture<Unit> setTimeoutsAsync(BrowserSettings browserSettings)
-
currentUrlAsync
abstract CompletableFuture<String> currentUrlAsync()
Returns a string representing the current URL that the browser is looking at.
-
pageSourceAsync
abstract CompletableFuture<String> pageSourceAsync()
Returns the source of the last loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page.
-
mainRequestHeadersAsync
abstract CompletableFuture<Map<String, Object>> mainRequestHeadersAsync()
-
mainRequestCookiesAsync
abstract CompletableFuture<List<Map<String, String>>> mainRequestCookiesAsync()
-
getCookiesAsync
abstract CompletableFuture<List<Map<String, String>>> getCookiesAsync()
-
bringToFrontAsync
abstract CompletableFuture<Unit> bringToFrontAsync()
Brings page to front (activates tab).
-
waitForSelectorAsync
abstract CompletableFuture<Long> waitForSelectorAsync(String selector)
Returns when element specified by selector satisfies {@code state} option.
-
waitForSelectorAsync
abstract CompletableFuture<Long> waitForSelectorAsync(String selector, Long timeoutMillis)
Returns when element specified by selector satisfies {@code state} option. Returns the time remaining until timeout.
-
waitForSelectorAsync
abstract CompletableFuture<Long> waitForSelectorAsync(String selector, Duration timeout)
-
waitForNavigationAsync
abstract CompletableFuture<Long> waitForNavigationAsync()
-
waitForNavigationAsync
abstract CompletableFuture<Long> waitForNavigationAsync(Long timeoutMillis)
-
waitForNavigationAsync
abstract CompletableFuture<Long> waitForNavigationAsync(Duration timeout)
-
existsAsync
abstract CompletableFuture<Boolean> existsAsync(String selector)
-
isHiddenAsync
abstract CompletableFuture<Boolean> isHiddenAsync(String selector)
-
isVisibleAsync
abstract CompletableFuture<Boolean> isVisibleAsync(String selector)
-
visibleAsync
abstract CompletableFuture<Boolean> visibleAsync(String selector)
-
isCheckedAsync
abstract CompletableFuture<Boolean> isCheckedAsync(String selector)
-
typeAsync
abstract CompletableFuture<Unit> typeAsync(String selector, String text)
-
clickAsync
CompletableFuture<Unit> clickAsync(String selector)
-
clickAsync
abstract CompletableFuture<Unit> clickAsync(String selector, Integer count)
-
clickMatchesAsync
CompletableFuture<Unit> clickMatchesAsync(String selector, String pattern)
-
clickMatchesAsync
abstract CompletableFuture<Unit> clickMatchesAsync(String selector, String pattern, Integer count)
-
clickMatchesAsync
abstract CompletableFuture<Unit> clickMatchesAsync(String selector, String attrName, String pattern, Integer count)
-
clickNthAnchorAsync
abstract CompletableFuture<String> clickNthAnchorAsync(Integer n, String rootSelector)
-
checkAsync
abstract CompletableFuture<Unit> checkAsync(String selector)
-
uncheckAsync
abstract CompletableFuture<Unit> uncheckAsync(String selector)
-
scrollToAsync
abstract CompletableFuture<Unit> scrollToAsync(String selector)
-
scrollDownAsync
abstract CompletableFuture<Unit> scrollDownAsync(Integer count)
-
scrollUpAsync
abstract CompletableFuture<Unit> scrollUpAsync(Integer count)
-
scrollToTopAsync
abstract CompletableFuture<Unit> scrollToTopAsync()
-
scrollToBottomAsync
abstract CompletableFuture<Unit> scrollToBottomAsync()
-
scrollToMiddleAsync
abstract CompletableFuture<Unit> scrollToMiddleAsync(Float ratio)
-
mouseWheelDownAsync
abstract CompletableFuture<Unit> mouseWheelDownAsync(Integer count, Double deltaX, Double deltaY, Long delayMillis)
-
mouseWheelUpAsync
abstract CompletableFuture<Unit> mouseWheelUpAsync(Integer count, Double deltaX, Double deltaY, Long delayMillis)
-
moveMouseToAsync
abstract CompletableFuture<Unit> moveMouseToAsync(Double x, Double y)
-
dragAndDropAsync
abstract CompletableFuture<Unit> dragAndDropAsync(String selector, Integer deltaX, Integer deltaY)
-
outerHTMLAsync
abstract CompletableFuture<String> outerHTMLAsync(String selector)
-
firstTextAsync
abstract CompletableFuture<String> firstTextAsync(String selector)
-
allTextsAsync
abstract CompletableFuture<List<String>> allTextsAsync(String selector)
-
firstAttrAsync
abstract CompletableFuture<String> firstAttrAsync(String selector, String attrName)
-
allAttrsAsync
abstract CompletableFuture<List<String>> allAttrsAsync(String selector, String attrName)
-
evaluateAsync
abstract CompletableFuture<Object> evaluateAsync(String expression)
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.
- Parameters:
expression- Javascript expression to evaluate
-
evaluateSilentlyAsync
abstract CompletableFuture<Object> evaluateSilentlyAsync(String expression)
Executes JavaScript in the context of the currently selected frame or window. The script fragment provided will be executed as the body of an anonymous function.
All possible exceptions are suppressed and do not throw.
- Parameters:
expression- Javascript expression to evaluate
-
captureScreenshotAsync
abstract CompletableFuture<String> captureScreenshotAsync(String selector)
This method scrolls element into view if needed, and then ake a screenshot of the element.
-
captureScreenshotAsync
abstract CompletableFuture<String> captureScreenshotAsync(RectD rect)
-
clickablePointAsync
abstract CompletableFuture<PointD> clickablePointAsync(String selector)
Calculate the clickable point of an element located by selector. If the element does not exist, or is not clickable, returns null.
-
boundingBoxAsync
abstract CompletableFuture<RectD> boundingBoxAsync(String selector)
Return the bounding box of an element located by selector. If the element does not exist, returns null.
-
newSessionAsync
abstract CompletableFuture<Connection> newSessionAsync()
Create a new Jsoup session with the last page's context, which means, the same headers and cookies.
-
loadResourceAsync
abstract CompletableFuture<NetworkResourceResponse> loadResourceAsync(String url)
Load url as a resource without browser rendering, with the last page's context, which means, the same headers and cookies.
-
pauseAsync
abstract CompletableFuture<Unit> pauseAsync()
Force the page pauses all navigations and PENDING resource fetches. If the page loading stops, the user can still interact with the page, and therefore resources can continue to load.
-
stopAsync
abstract CompletableFuture<Unit> stopAsync()
Force the page stop all navigations and RELEASES all resources. Interaction with the stop page results in undefined behavior and the results should not be trusted.
If a web driver stops, it can later be used to visit new pages.
-
terminateAsync
abstract CompletableFuture<Unit> terminateAsync()
Force the page stop all navigations and RELEASES all resources. If a web driver is terminated, it should not be used any more and should be quit as soon as possible.
-
-
-