我有这个iframe,用来输入卡号。
我正在用铬无头模式来尝试这个。
<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>发布于 2022-04-11 12:24:10
为该Xpath编写iframe,如下所示。就像你提到的
,我有这个iframe,用来输入卡号。
因此,对于卡号有一个属性。
//iframe[@attribute='value']例:
driver.switchTo().frame("iframe");
WebElement ele = driver.findElement(By.xpath("//iframe[@attribute='value']"));
ele.sendKeys('Text');或
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@attribute='value']")));
WebElement inputtext = driver.findElement(By.xpath("//input[@attribute='value']"));
inputtext.sendKeys("text");希望这个回答你的问题,如果这没有回答你的问题,请分享HTML从检查元素。
https://stackoverflow.com/questions/71827370
复制相似问题