如何用selenium python点击shadowroot中的button元素?

2024-06-01 00:42:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在对web应用程序进行自动化,需要在shadow root中单击“登录”按钮。在

链接到html: https://imgur.com/a/oTrQiYC

尝试了许多不同的解决方案-没有成功。在

如何解决这个问题? 提前谢谢

代码是否:

###def expand_shadow_element (element):###

  global driver

  shadowRoot= driver.execute_script('return arguments[0].shadowRoot', element)

return shadowRoot

### The script: ###

global driver

root = driver.find_element_by_tag_name("decoy-server-login")

shadowRoot = expand_shadow_element(root)
               shadowRoot.find_element_by_xpath("//[@id='loginForm']/p/button").click()

获取错误:

Message: invalid selector: Unable to locate an element with the xpath expression //*[@id='loginForm']/p/button because of the following error: NotSupportedError: Failed to execute 'evaluate' on 'Document': The node provided is '#document-fragment', which is not a valid context node type.


Tags: theidexecutebyreturndriverscriptroot