li ki
li ki

Reputation: 19

In the Playwright web automation framework, is there a method that can help me handle elements that require scrolling to be clickable?

If the element is currently visible, such as the following:

Directly clickable

I only need to execute page.get_by_text("target_string").click() to complete the click.

However, if an element is currently invisible:

Currently not visible

directly using page.get_by_text("target_string").click() will report an error, and you need to slide down to display the element and make it clickable.

There are two solutions. One is to press and hold the scroll bar with the mouse and drag it until it is visible. The other is to move the mouse to the entire selection window and then scroll the wheel to make the target element visible directly.

Is there a method in Playwright that automatically helps me drag the scroll bar when the element I am looking for is not visible?

Upvotes: 0

Views: 78

Answers (1)

Vishal Aggarwal
Vishal Aggarwal

Reputation: 4199

First narrow down values so that it will be visible in the list by typing into the field character by character, as if it was a user with a real keyboard with locator.press_sequentially().

page.locator('#textarea').pressSequentially('target_string')

NOTE: Also never click or verify anywhere purely based on text as if the text appears on multiple places , it may perform the step at unexpected place and incorrectly pass the test. Use any specific locator property as well with the text.

Upvotes: 0

Related Questions