如何使用Selenium识别iframe?
HTML:
<iframe allowpaymentrequest="true" allowtransparency="true" src="https://shopify.wintopay.com/
cd_frame_id_="ca9e4ad6a1559de159faff5c1f563d59"
name="WinCCPay"
id="win-cc-pay-frame"
我正在尝试在抄送字段中输入文本。显然它在一个 iframe 中,我选择了 HTML 中的最后一个,并尝试从上面的标识符中选择它,但我不断收到无法找到该元素的信息
iframe= wd.find_element_by_id("win-cc-pay-frame")
wd.switch_to.frame(iframe)
该框架当前正在浏览器中显示,因此不需要隐式等待。
HTML:
<iframe allowpaymentrequest="true" allowtransparency="true" src="https://shopify.wintopay.com/
cd_frame_id_="ca9e4ad6a1559de159faff5c1f563d59"
name="WinCCPay"
id="win-cc-pay-frame"
I'm trying to input text in a CC field. Apparently its in an iframe I picked the last one in the HTML and tried to select it from the identifiers above but I keep getting the element couldn't be found
iframe= wd.find_element_by_id("win-cc-pay-frame")
wd.switch_to.frame(iframe)
The frame is currently being shown in the browser so no need for implicit wait.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要识别
,因此您必须:
归纳 WebDriver等待所需的框架可用并切换到它。
您可以使用以下任一定位器策略:
使用CSS_SELECTOR:
使用XPATH:
注意:您必须添加以下导入:
To identify the
<iframe>
so you have to:Induce WebDriverWait for the desired frame to be available and switch to it.
You can use either of the following Locator Strategies:
Using CSS_SELECTOR:
Using XPATH:
Note : You have to add the following imports :
问题可能是元素的名称和 id 是动态的,并且会针对每个唯一的结帐窗口进行更改?您可以检查是否在 iframe 标记中添加
class
属性并通过该属性查找元素吗?它一定类似于:
良好的编码! ˙_(ツ)_/˙
The problem can be that the name and id of the element are dynamic and change for each unique checkout window? Can you check if adding
class
attribute at iframe tag and find element by this attribute?It must be similar to:
good coding! ¯_(ツ)_/¯