I am trying to paste some text from the clipboard into a hidden textarea input element on a website with Playwright, but I keep getting issues because the element has attribute:
style="visibility:hidden, display:none;"
I am trying to resolve that with page.evaluate command in Playwright, but can't seem to change the element visibility status. Here is the returned error:
page.evaluate("[id=txbLongDescription] => document.querySelector('[id=txbLongDescription]')", style='visibility:visible')
TypeError: Page.evaluate() got an unexpected keyword argument 'style'
Here is my code so far:
def run(playwright: Playwright) -> None:
browser = playwright.chromium.launch(headless=False)
context = browser.new_context(accept_downloads=True)
page = context.new_page()
# Click in description input field
#paste description from clipboard
paste = pc.paste()
page.evaluate("[id=txbLongDescription] => document.querySelector('[id=txbLongDescription]')", style='visibility:visible')
page.fill('textarea[id=\"txbLongDescription\"]', f'{paste}')
#---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
print('Done')
Here is my solution:
page.eval_on_selector(
selector="textarea", # Modify the selector to fit yours.
expression="(el) => el.style.display = 'inline-block'",
)
Here is the document of eval_on_selector().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With