【问题标题】:How to input text in a textbox that is under Shadow-root in a web page using protractor or selenium.如何使用量角器或硒在网页中 Shadow-root 下的文本框中输入文本。
【发布时间】:2018-09-08 15:52:43
【问题描述】:

如何使用量角器或硒在网页中Shadow-root下的文本框中输入文本?任何事情都会有所帮助。 我正在尝试使用 xpath 在文本字段中输入值,而 xpath 是正确的,因为我已经在控制台中对其进行了验证。

【问题讨论】:

标签: selenium xpath protractor automated-tests shadow-dom


【解决方案1】:

只需在 Web 控制台中使用 javascript,您就可以使用以下内容:

document.querySelector('message-list').shadowRoot.querySelector('.textbox').querySelector('textbox').value = 'hello'

要使用 appium 运行它,您需要使用 driver.executeScript

【讨论】:

  • 请注意,只有当 shadowRoot 被创建为“开放”并且开发人员选择这样做时,这才有效:this.attachShadow({mode: 'closed'}); then element.shadowRoot` 将返回 null
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-10
  • 2019-06-03
  • 1970-01-01
  • 2021-01-03
  • 2020-12-24
  • 2019-06-26
相关资源
最近更新 更多