如何读取#shadow-root下的文本(用户代理) [英] How to read text that is under #shadow-root (user-agent)

查看:249
本文介绍了如何读取#shadow-root下的文本(用户代理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium(Python)来自动执行网页.我正在尝试从#shadow-root(用户代理)下的输入字段中获取文本.我使用的Xpath:

I am using Selenium (Python) for automating a web page. I am trying to get text from an input field that is under #shadow-root (user-agent). Xpath I used:

driver.find_element_by_xpath("**//*/p-calendar/span/input**").text

不返回任何内容.附上我的DOM元素的屏幕截图.要求:要从影子根获取文本:01:01

is not returning anything. Attached the screenshot of my DOM element. Requirement: To get text from the shadow root : 01:01

推荐答案

根据 @hayatoito (Shadow DOM的创建者)

As per @hayatoito's (creator of Shadow DOM) comment:

引入封闭的影子树的最初动机是 绝不允许通过任何API从外部访问封闭的影子树中的节点" 据我所知.那样,我们无法访问内部隐藏阴影树中的节点,该树在Blink中的< video> 元素中使用.

实际上,我以这种方式设计了一个封闭的影子树.如果可以访问封闭的影子树中的节点,则应将其视为规范的错误.

In fact, I designed a closed shadow tree in such a way. If there is a way to access a node in a closed shadow tree, it should be considered as a bug of the spec.

我认为拥有一个允许访问Chrome应用或扩展程序层的API完全可以.但是,对于普通的Web应用程序,我认为当前协议为 绝不允许" .

I think it's totally okay to have an API to allow an access in the layer of Chrome apps or extensions. However, for a normal web app, I think the current agreement is "Never allow it".

如果我们允许,那就意味着我们不需要封闭的影子树.我认为只有一棵开放的影子树就足够了.

If we allowed it, that means we do not need a closed shadow tree. Just having an open shadow tree is enough, I think.

Furhter @Supersharp 在讨论中他自己的回答下面的评论中

Furhter @Supersharp in his comment below his own answer within the discussion How to get element in user-agent shadow root with JavaScript? mentions:

#shadow-root(用户代理)是浏览器供应商的本机实现,因此未记录在文档中,将永远无法访问.根据规范,只有打开的Shadow DOM是

#shadow-root (user-agent) are browser vendors native implementation so they are not documented and will never be accessible. Only open Shadow DOM are, as per the specs


WebDriver透视图

最近,@ AutomatedTester [Mozilla公司首席培根官David Burns]在上发起了讨论WebDriver-Web组件的可测试性

目前 Selenium Team 已开放,可以接受对它的请求请求.

Currently Selenium Team is open for accepting pull requests for the same.

您可以在以下位置找到几个相关的详细讨论:

You can find a couple of relevant detailed discussions in:

您可以在如何找到相关讨论用硒自动化阴影DOM元素?

这篇关于如何读取#shadow-root下的文本(用户代理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆