Using ‘page.selectOption()’ method, we can select multiple items from a select tag. ExampleString valuesToSelect[] = { "red", "green", "yellow" };page.selectOption("select… Read More
'type' method is used to type some text on the selected element. Signaturevoid type(String selector, String text)void type(String selector, String text, TypeOptions options)… Read More
There are three keyboard events in JavaScript. a. keydown: Key down event is fired whenever a key is pressed and it keep on firing as long as we are holding the key down… Read More
Using 'setInputFiles' method, we can set the value of the file input. ExampleString filePath = resourceFilePath("files" + File.separator + "emp.json");page.locator("#myFile").setInput… Read More
Using Locator.focus() method we can focus the element. Let’s see it with an example. Examplepage.locator("#demo").focus(); Find the below working a… Read More
Using 'setInputFiles' method, we can set the value of the file input. ExamplePath[] paths = { Paths.get(filePath1), Paths.get(filePath2) };page.locator("#myFile").setInputFiles(paths)… Read More
'page.dragAndDrop()' method drags the source element to the target element. SignaturedragAndDrop(String source, String target)dragAndDrop(String source, String target, DragAndDropOpti… Read More
Locator.dispatchEvent method, dispatch an event on the element. Signaturevoid dispatchEvent(String type)void dispatchEvent(String type, Object eventInit)void dispatchEvent(String type… Read More
Using Locator.clear() method, we can clear the content of selected input, textarea, or contenteditable elements. Signaturevoid clear() void clear(ClearOptions options) … Read More
Locator.tap() method taps the element. Signaturevoid tap()void tap(TapOptions options) Example page.locator("#favoriteColors").locator("option[value=\"red\"… Read More
Class Runtime in JavaEvery Java application has a single instance of class Runtime. Runtime class allows the application to interact with the enviro… Read More
Locator.allInnerTexts() method return an array of innerText values for all matching nodes. ExampleList allInnerTexts = page.locator(".oddPara").allInnerTexts(); … Read More
Locator.boundingBox()
method returns the bounding box of the element, or null if the element is not
visible.
SignatureBoundingBox boundingBox()
BoundingBox boundingBox(BoundingBoxOp… Read More
Locator.allTextContents()
method returns a list of textContent values for all matching nodes.
allInnerTexts
() vs allTextContents ()
allInnerTexts()
method returns the text, withou… Read More
Locator.count()
method return the number of elements matching given selector.
Signatureint count();Exampleint count = page.locator(".para").count(); Find the
below working appl… Read More
Locator
class provides ‘elementHandle’, 'elementHandles' methods to get the matching
DOM elements.
Signature
to get one DOM element
ElementHandle
elementHandle()
Eleme… Read More
Using ‘page.evaluate’
method, we can evaluate an expression.
SignatureObject evaluate(String expression)
Object evaluate(String expression, Object arg)
Object evaluate(S… Read More
Locator.filter
method narrows existing locator according to the options.
SignatureLocator filter()
Locator filter(FilterOptions options)
Example
Filter… Read More
Java is one of the most widely used programming languages in the world. It is an object-oriented language that is used for developing a wide range of applications, from mobile apps to enterp… Read More
page.frameLocator()
method return a frame locator that will enter the iframe and allow selecting
elements in that iframe.
ExampleFrameLocator frameLocator = page.frameLocator("#java… Read More
Using
Locator getAttribute method, we can get the attribute value of given element.
Signature
String getAttribute(String name)
String getAttribute(String name, GetAttributeOpti… Read More
Locator.highlight()
method highlight all the matching elements on the screen.
Examplepage.locator(".impt").highlight();
Find the
below working application… Read More
Socket programming is a way of communicating between two or more computers over a network. It is a fundamental concept in computer networking and is widely used in various applications such… Read More
Implement
an utility class such that, it takes a code snippet and executes with the
configured number of retries until it is successful.
Find the
below working application.
… Read More
Locator.innerText()
return the value of 'element.innerText' associated with the given element.
SignatureString innerText()
String innerText(InnerTextOptions options)… Read More
Locator.inputValue()
(or) page.inputValue() method return the input.value for the selected
, or element.
SignatureString inputValue()
String inputValue(InputValueOptions options)… Read More
Locator.isDisabled()
method return true, if the selected element is disabled, else false.
Signatureboolean isDisabled()
boolean isDisabled(IsDisabledOptions options)… Read More
Locator.isEditable()
method return true when the element is editable, else false.
Signatureboolean isEditable()
boolean isEditable(IsEditableOptions options)
Exam… Read More
Locator.isEnabled()
method return true, when the element is enabled, else false.
Signatureboolean isEnabled()
boolean isEnabled(IsEnabledOptions options)
Fi… Read More
Locator.isHidden
method return true when the element is hidden, else false.
Signatureboolean isHidden()
boolean isHidden(IsHiddenOptions options)
Example… Read More
There are
multiple ways to check whether an element is visible or not in a page.
Approach
1: Using
page.locator(someLocator).isVisible() method
isVisible()
method return true, if… Read More
Locator.last()
method return the locator of last matching element.
SignatureLocator last()
Example
Locator lastMatchingElement = page.locator(".para").l… Read More
Locator.nth()
method returns locator to the n-th matching element. Index is 0-based.
SignatureLocator nth(int index)
Example
Locator secondMatchingEleme… Read More
Locator.page()
method return the page reference from the locator.
SignaturePage page()
Example
String pageTitle = firstMatchingElement.page().title();… Read More
Locator.selectText()
method select all the text content attached to element mapped to this selector.
Signaturevoid selectText()
void selectText(SelectTextOptions options)
… Read More
Locator.uncheck()
method uncheck the radio button or checkbox.
Signature
void
uncheck()
void
uncheck(UncheckOptions options)
Example
page.getByLabel("java").uncheck();… Read More
'page.getByRole()'
method locate the elements by their ARIA role.
SignatureLocator getByRole(AriaRole role)
Locator getByRole(AriaRole role, GetByRoleOptions options)
… Read More
Using
page.getByText() method, we can locate the elements by text content.
SignatureLocator getByText(String text)
Locator getByText(String text, GetByTextOptions options)
Locator g… Read More
Using 'page.getByLabel()'
method, we can interact with an element using label text.
For
example, we can use this method to fill the text field data, to locate a radio
button by asso… Read More
You can
use page.getByAltText method to locate the elements by their alt text.
ExampleElementHandle elementHandle = page.getByAltText("plantuml").elementHandle();… Read More
page.getByPlaceholder()
method return the locate the input elements by the placeholder text.
SignatureLocator getByPlaceholder(String text)
Locator getByPlaceholder(String text, Get… Read More
page.getByTitle()
method locate the elements that match to given title.
SignatureLocator getByTitle(String text)
Locator getByTitle(String text, GetByTitleOptions options)
Locator g… Read More
Table of ContentsJava Classes for Reading Data from FilesJava Classes for Writing Data to FilesReading Data from Files in JavaReading Text FilesReading Binary FilesReading Files with Java NI… Read More
‘data-testid’
attribute is used to identify a DOM node for testing purposes. 'page.getByTestId()'
method Locate element by the test id. By default, the 'data-testid' attribute
is… Read More
Playwright.locator()
method return the locator by a selector.
SignatureLocator locator(String selector)
Locator locator(String selector, LocatorOptions options)… Read More
Using ‘page.locator(classSelector).allTextContents()’
method, we can get an array of textContent values for all matching nodes.
ExampleList allParagraphs = page.locator(… Read More
Using the
keyboard modifier 'META', we can open the url in a new tab.
ExampleList modifiers = Arrays.asList(KeyboardModifier.META);
clickOptions.setModifiers(modifiers);
page.locato… Read More
Quick Summary:
Structural design patterns in Java organize classes and objects, promote code reusability, and simplify complex systems. They decouple components, manage relationships, and e… Read More
Using
ElementHandle, we can get the parent, grandparent, siblings, childs etc.,
ExampleElementHandle elementHandle = page.querySelector("#para1");
ElementHandle grandParent = elemen… Read More
We can
bind the request body to a InputStream using @Body annotation.
Example@Post(value = "/read", processes = MediaType.TEXT_PLAIN)
@ExecuteOn(TaskExecutors.IO)
String read(@Body… Read More
Using
evaluate method and ‘getComputedStyle’ we can get all the styles associated
with an element.
ExampleLocator locator1 = page.locator("#para1");
Map styles1 = (Map)… Read More
Alessandro InnocenziFollowBetter Programming--ListenShareThe problem with not releasing the resources we use is that over time the server fills up with things to do and can no longer process… Read More
page.bringToFront()
method is used to activate a tab (or) brings the page to front.
Example// Get all the opened pages in the context
List pages = page.context().pages();
for (Page tempPa… Read More
Using
page.waitForSelector() method, we can wait for the selector certain amount of
time.
Examplepage.waitForSelector("#result", waitForSelectorOptions)
Find the
below wo… Read More
(Read this article on the blog)
Last updated on 2023/09/22 to include changes up to JDK 21.
This article is also available in Chinese by Alex Tan.
Since the release of version 8, up to ver… Read More
You must be meticulous when writing code to avoid errors and make sure your programs work, especially when it comes to the syntax of your chosen coding language. Syntax errors in Java m… Read More