Skip to content

GetFocusedElement.cs

Avrigeanu Laurian edited this page Apr 11, 2023 · 1 revision

GetFocusedElement(bool lockToLastPage = true) Method

Returns the currently focused element in the current page.

Parameters

  • lockToLastPage : An optional boolean parameter indicating whether to search only the last page in the _context.Pages collection. Default value is true.

Returns

  • An IElementHandle representing the currently focused element in the current page.

Exceptions

  • PlaywrightException: If the Playwright library is unable to find the focused element.

Remarks

This method first calls the FindElement() method with the CSS selector "*:focus", which finds the first focused element in the current page. If lockToLastPage is true, the search is limited to the last page in the _context.Pages collection. It then logs a warning message with the X and Y coordinates of the focused element's bounding box, and returns the focused element.

Clone this wiki locally