Webdriverio:访问 shadow dom 元素 [英] Webdriverio: Accessing shadow dom elements

查看:130
本文介绍了Webdriverio:访问 shadow dom 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have an app structure like this: 
<shell>
#shadow-root (open)
<mini-app>
#shadow-root (open)
<input id="username" autocomplete="off" name="username" type="text" aria-required="true" required="" value="">
</mini-app>
<shell>
Nested tags with shadow-root element username inside it.I want to access input element username using webdriverio.

我可以使用以下方法在 dev 中访问用户名:

I am able to access username in dev using the following:

   let a = document.querySelector('shell')
    let b = a.shadowRoot.querySelector('mini-app')
    b.shadowRoot.getElementById('username')

  How can i access the same using webdriverio ? I went through this `https://webdriver.io/blog/2019/02/22/shadow-dom-support.html` but the documentation looks outdated because I am unable to use shadowRoot with shadow$
Any help would be appreciated.

有没有其他方法可以通过 webdriver 访问 shadow dom 元素?

Is there any other way to access shadow dom elements through webdriver?

推荐答案

文档似乎还不错,你能说明一下你是如何使用 shadow$ 方法的吗?

Documentation seems to be fine, can you show how exactly you are using shadow$ method?

我认为很简单

$('shell').shadow$('.mini-app').shadow$('#username')

应该可以

这篇关于Webdriverio:访问 shadow dom 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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