我正在尝试将剪贴板中的一些文本粘贴到 Playwright 网站上的隐藏文本区域输入元素中,但由于该元素具有属性,我不断遇到问题:
style="visibility:hidden, display:none;"
我正在尝试使用 Playwright 中的 page.evaluate 命令解决此问题,但似乎无法更改元素可见性状态。这是返回的错误:
page.evaluate("[id=txbLongDescription] => document.querySelector('[id=txbLongDescription]')", style='visibility:visible')
TypeError: Page.evaluate() got an unexpected keyword argument 'style'
到目前为止,这是我的代码:
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')