Skip to content

FindElement.cs

Avrigeanu Laurian edited this page Apr 11, 2023 · 2 revisions

FindElement(string selector, bool lockToLastPage = false, int retries = 3) Method

Finds the first element in the current page that matches the specified CSS selector.

Parameters

  • selector : A CSS selector that identifies the element to be found.
  • lockToLastPage : An optional boolean parameter indicating whether to search only the last page in the _context.Pages collection. Default value is false.
  • retries : An optional integer parameter indicating the number of times to retry the search in case of a failure. Default value is 3.

Returns

  • An IElementHandle representing the first element that matches the specified selector.

Exceptions

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

Remarks

This method searches for the element in all of the pages in the _context.Pages collection in reverse order. If lockToLastPage is true, it searches only the last page in the collection. If the search fails, it retries the specified number of times, waiting for the page to load between retries. If the element is found, it logs a warning message and returns the element. If the element is not found, it logs an error message and returns null.

Clone this wiki locally