硒无法找到iframe [英] Selenium can't locate iframe

查看:112
本文介绍了硒无法找到iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Selenium无法通过IDName定位iframe.

Selenium fails to locate the iframe by ID and Name.

这是Shopify上的自动结帐测试.具体问题在付款"字段中.我找到了iframe的ID和名称,即card-fields-number-b1kh6njydiv00000.

This is for an automated checkout test on Shopify. The specific issue lies within the payment field. I found the ID and name of the iframe, which is card-fields-number-b1kh6njydiv00000.

iframe图片:

文本字段图像:

代码试用:

driver.switchTo().frame("card-fields-number-b1kh6njydiv00000");
System.out.println("Found iframe");

错误是:

org.openqa.selenium.NoSuchFrameException: No frame element found by name or id card-fields-number-b1kh6njydiv00000

推荐答案

我相信可以使用XPath.您将需要使用XPath查找IFrame IWebElement,然后将IWebElement传递到SwitchTo().Frame()

It is possible to use XPath for this I believe. You will need to find the IFrame IWebElement with XPath, and then pass the IWebElement into the SwitchTo().Frame()

var ele = driver.FindElement(By.XPath("//iframe[contains(id, 'card-fields-number')]"));

driver.switchTo().frame(ele);

这篇关于硒无法找到iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆