【问题标题】:Ruby, Watir, and how to fill out text fields inside of a Shadow DOM? (Safari)Ruby、Watir 以及如何在 Shadow DOM 中填写文本字段? (苹果浏览器)
【发布时间】:2020-10-31 19:27:19
【问题描述】:

编辑:找到部分解决方案:我使用的是 Safari。通过 Chrome 运行任务将 Shadow DOM 中的内容转换为 Light Dom,以便我现在可以访问它!

我正在尝试自动执行浏览器任务并使用 Watir 自动填写一些表单,但我在尝试填写 Shadow DOM 中的文本框时遇到了困难。

文本字段的图像:

https://i.imgur.com/FWccWea.png

这是邮政编码文本字段对应的 HTML:

<input class="textbook" id="Fm2_Ctrol19_TextBox" name="Fm2_Ctrol19_TextBox" 
onchange="SearchJs.setBackgroundColor(this, SearchJs.checkTextBox_;" 
onkeypress="return 
SearchJS.onTextBoxKeyPress(event, this);" 
onkeyup="SearchJs.setBackgroundColor(this,SearchJs.checkTextBox);" 
onpaste="return SearchJs.onTextBoxPaste(event, this);" style="width:100px;
background=color: #ffffff;"
title="The zip code in which the property is located." type="text"> =$0

Shadow Content (User Agent) # The text field is in here, I imagine.

</input>

我对 javascript 和 Shadow DOM 不够熟悉,无法知道我在 Google 上搜索的文章是否相关。

我过去曾尝试使用普通的 Watir,但在 30 秒超时后出现 Watir::Exception::UnknownObjectException (timed out after 30 seconds, waiting for #&lt;Watir::TextField: located: false; {:id=&gt;"Fm2_Ctrol19_TextBox", :tag_name=&gt;"input"}&gt; to be located)

 b.text_field(id: 'Fm2_Ctrol19_TextBox').set 'POSTAL CODE HERE' # What I've tried

有没有人有任何信息可以帮助我填写该框?

【问题讨论】:

  • 这会正确触发onchange 处理程序吗?
  • @tadman 是的。当文本插入框中时,它将背景颜色从白色变为蓝色。
  • 也许也可以触发onpaste 处理程序以确保?值得注意的是,JavaScript 似乎也存在语法错误。 checkTextBox_;checkTextBox);
  • 您收到的错误信息是什么?或者当你自动化时发生了什么?
  • 这是您应该在问题中包含的错误消息。您能否再次确认我是在等待 30 秒后抛出此错误还是立即抛出此错误?

标签: ruby selenium watir shadow-dom


【解决方案1】:

找到部分解决方案:我使用的是 Safari。通过 Chrome 运行任务将 Shadow DOM 中的内容转换为 Light Dom,以便我现在可以访问数据!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2017-07-02
    • 1970-01-01
    • 2014-03-11
    • 2021-08-30
    • 2012-11-02
    相关资源
    最近更新 更多