首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果iframe是iframe中的唯一元素,我如何向iframe发送密钥?

如果iframe是iframe中的唯一元素,我如何向iframe发送密钥?
EN

Stack Overflow用户
提问于 2022-04-11 11:52:45
回答 1查看 84关注 0票数 0

我有这个iframe,用来输入卡号。

我正在用铬无头模式来尝试这个。

代码语言:javascript
复制
<iframe hspace="0" vspace="0" frameborder="0" scrolling="no" allowtransparency="true" marginwidth="0" marginheight="0" 

html inside the iframe with #document
#document
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><style>*{margin:0;padding:0;-webkit-box-sizing:border-box;box-sizing:border-box;border:none;background-color:transparent}body,form,input{position:absolute;top:0;left:0;height:100%;width:100%}label{position:absolute;left:-9999px}:focus{outline:0}::-ms-clear,input::-ms-clear{display:none}.autocomplete,.field-description,.focus-helper{opacity:0;pointer-events:none;width:1px;height:1px;left:-1px;z-index:-1}.autocomplete{width:2px;height:2px;left:-2px}</style><style></style></head><body marginwidth="0" marginheight="0"><script src="iframe.min.js"></script><form><input class="focus-helper start" tabindex="0" readonly="" aria-hidden="true" autocomplete="off" autocompletetype="off" x-autocompletetype="off"><input name="number" type="tel" autocorrect="off" autocapitalize="none" spellcheck="false" aria-invalid="false" aria-label="Card number" maxlength="22" autocomplete="cc-number" autocompletetype="cc-number" x-autocompletetype="cc-number" placeholder=" " aria-placeholder=" " class="invalid"><input type="text" name="name" id="name-autocomplete" class="autocomplete" autocomplete="cc-name" autocompletetype="cc-name" x-autocompletetype="cc-name" tabindex="-1" aria-hidden="true"><input type="text" name="expirationMonth" id="expirationMonth-autocomplete" class="autocomplete" autocomplete="cc-exp-month" autocompletetype="cc-exp-month" x-autocompletetype="cc-exp-month" tabindex="-1" aria-hidden="true"><input type="text" name="expirationYear" id="expirationYear-autocomplete" class="autocomplete" autocomplete="cc-exp-year" autocompletetype="cc-exp-year" x-autocompletetype="cc-exp-year" tabindex="-1" aria-hidden="true"><input class="focus-helper end" tabindex="0" readonly="" aria-hidden="true" autocomplete="off" autocompletetype="off" x-autocompletetype="off"></form></body></html>
EN

回答 1

Stack Overflow用户

发布于 2022-04-11 12:24:10

为该Xpath编写iframe,如下所示。就像你提到的

,我有这个iframe,用来输入卡号。

因此,对于卡号有一个属性。

代码语言:javascript
复制
//iframe[@attribute='value']

例:

代码语言:javascript
复制
driver.switchTo().frame("iframe");

WebElement ele = driver.findElement(By.xpath("//iframe[@attribute='value']"));

ele.sendKeys('Text');

代码语言:javascript
复制
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@attribute='value']")));

WebElement inputtext = driver.findElement(By.xpath("//input[@attribute='value']"));

inputtext.sendKeys("text");

希望这个回答你的问题,如果这没有回答你的问题,请分享HTML从检查元素。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71827370

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档