Method: Playwright::Page#eval_on_selector
- Defined in:
- lib/playwright_api/page.rb
#eval_on_selector(selector, expression, arg: nil) ⇒ Object
The method finds an element matching the specified selector within the page and passes it as a first argument to expression. If no elements match the selector, the method throws an error. Returns the value of expression.
If expression returns a [Promise], then [‘method: Page.evalOnSelector`] would wait for the promise to resolve and return its value.
Examples:
“‘js const searchValue = await page.$eval(’#search’, el => el.value); const preloadHref = await page.$eval(‘link’, el => el.href); const html = await page.$eval(‘.main-container’, (e, suffix) => e.outerHTML + suffix, ‘hello’); “‘
“‘python async search_value = await page.eval_on_selector(“#search”, “el => el.value”) preload_href = await page.eval_on_selector(“link“, ”el => el.href“) html = await page.eval_on_selector(”.main-container“, ”(e, suffix) => e.outer_html + suffix“, ”hello“) “`
“‘python sync search_value = page.eval_on_selector(“#search”, “el => el.value”) preload_href = page.eval_on_selector(“link“, ”el => el.href“) html = page.eval_on_selector(”.main-container“, ”(e, suffix) => e.outer_html + suffix“, ”hello“) “`
Shortcut for main frame’s [‘method: Frame.evalOnSelector`].
435 436 437 |
# File 'lib/playwright_api/page.rb', line 435 def eval_on_selector(selector, expression, arg: nil) wrap_impl(@impl.eval_on_selector(unwrap_impl(selector), unwrap_impl(expression), arg: unwrap_impl(arg))) end |