javascript - 访问输入字段 Puppetier
问题描述
我有一个 puppeteer 刮刀,我必须插入信用卡信息。我访问 Cvv 和 Expire 字段没有问题,但我无法输入 cc number 字段。
在 iframe 中提交的输入就像这样
<iframe src="bla bla bla my url" scrolling="no" name="FrameCCPay" id="FrameCCPay" frameborder="0" allowtransparency="true" style="width: 100px; height: 18px; border: none; margin: 0px; padding: 0px; min-width: 100%; overflow: hidden;"></iframe>
在框架的文档中有这个代码
<div class="placePan">
<div class="input-container">
<input type="tel" autocomplete="off" spellcheck="false" name="482e7f7b-59aa-3f0d-bde7-8dcf6bcee7a7" class="cleavePan hasError" id="482e7f7b-59aa-3f0d-bde7-8dcf6bcee7a7" maxlength="24" placeholder="Numero Carta" style="display: inline-block;">
<input type="tel" autocomplete="off" spellcheck="false" class="cleavePan" id="482e7f7b-59aa-3f0d-bde7-8dcf6bcee7a7_bin" maxlength="24" placeholder="Numero Carta" style="display: none;">
</div>
</div>
我的 Puppetier 代码
const frame = getFrame(this.page, "FrameCCPay")
await frame.waitForSelector(".placePan input")
await frame.focus('.placePan input')
await frame.type(".placePan input", mynumber)
正如我所说,此代码适用于其他文件,并且文件 ae 以相同的方式完成。唯一的区别是 cc umber 有两个具有相同类的输入(.placePan 输入),所以我认为这就是问题所在。
我可以在正确的输入类型中使用 TYPE 函数吗?如何排除隐藏的.placePan 输入?
解决方案
如果您认为问题出在隐藏输入上,请使用具有仅在所需输入中存在的属性的选择器:".placePan input[name]"
.