【发布时间】: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 #<Watir::TextField: located: false; {:id=>"Fm2_Ctrol19_TextBox", :tag_name=>"input"}> 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