Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing display property for a hidden text area element with Playwright in Python

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')
like image 727
Alee Avatar asked Mar 20 '26 13:03

Alee


1 Answers

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().

like image 96
Leon Avatar answered Mar 23 '26 03:03

Leon