如何使用selenium-python在shadowroot中单击按钮元素?
我正在对web应用程序进行自动化,需要单击ShadowRoot中的按钮-登录 链接到html: 尝试了许多不同的解决方案-没有成功 如何解决这个问题? 提前谢谢 该代码是否:如何使用selenium-python在shadowroot中单击按钮元素?,python,selenium,dom,browser-automation,Python,Selenium,Dom,Browser Automation,我正在对web应用程序进行自动化,需要单击ShadowRoot中的按钮-登录 链接到html: 尝试了许多不同的解决方案-没有成功 如何解决这个问题? 提前谢谢 该代码是否: ###def expand_shadow_element (element):### global driver shadowRoot= driver.execute_script('return arguments[0].shadowRoot', element) return shadowRoot #
###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()
获取错误:
消息:选择器无效:无法找到具有xpath的元素
expression/*[@id='loginForm']/p/按钮,原因如下
错误:不支持错误:未能对“文档”执行“评估”:
提供的节点为“#文档片段”,该节点无效
上下文节点类型
你试过cssPath吗?我想我在这里发现了一个bug: