使用Selenium Webdriver与Stripe Card Element iFrame交互-黄瓜/Selenium Java [英] Using Selenium Webdriver to interact with Stripe Card Element iFrame - Cucumber/Selenium Java

查看:125
本文介绍了使用Selenium Webdriver与Stripe Card Element iFrame交互-黄瓜/Selenium Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要在Java中使用Cucumber和Selenium Webdriver自动化的表单-在此表单中,我们有一个从Stripe使用的card元素.我们将其称为div,其余的将由stripe完成.我不确定这是否是iFrame,但是当我使用

I have an form that I want to automate using Cucumber and Selenium Webdriver in Java - in this form, we have a card element which we use from Stripe. We call the div, and stripe does the rest. I'm unsure if this is an iFrame, but when I use the

Hooks.driver.findElement(By.xpath("xpathOfTheCardNumberField")).sendKeys("123");

命令,它不与之交互,并在控制台日志中返回无法定位元素"错误.

command, it does not interact with it and returns the "Unable to locate element" error in the console log.

我已经请前端程序尝试在字段中添加一些ID或名称标签,但他告诉我,他不能与card元素内部字段的标记进行交互,只能与card元素本身进行交互-因为Stripe处理了其他所有事情.

I have asked our front-ender to perhaps try and add some ID's or Name tags to the fields, but he informs me that he cannot interact with the markup for the fields inside of the card element, only the card element itself - as Stripe deal with everything else.

随附的是卡片元素的图片,以及相关卡片元素的标记.

Attached is a picture of the card element, as well as the markup for the card element in question.

是否可以使Selenium与该元素进行交互?

Is it possible to get Selenium to interact with this element?

任何帮助将不胜感激. 卡片元素前端

Any help is greatly appreciated. Card element front end

标记卡元素

推荐答案

我实际上已经解决了这个问题,所以我将回答这个问题并将其关闭,以防其他人遇到问题.

I've actually figured this out myself, so I'm going to answer the question and close it off in case anyone else is having issues with it.

我认为这是一种毯子式方法,可用于任何iframe,而不仅仅是Stripe.

I think this is a blanket method that can be used for any iframes, not just Stripe.

首先,您必须告诉网络驱动程序将框架切换到您要访问的iframe:

Firstly, you must tell your webdriver to switch frames to the iframe you are trying to access:

Hooks.driver.switchTo().frame(Hooks.driver.findElement(By.xpath("xpathOfIframe")));

然后,您可以为该iframe中的事物创建webElement,并与之交互:

Then, you can create webElements for the things within that iframe, and interact with them:

WebElement creditcardNumber = Hooks.driver.findElement(By.name("cardnumber"));
creditcardNumber.sendKeys("1234567890000066");

这篇关于使用Selenium Webdriver与Stripe Card Element iFrame交互-黄瓜/Selenium Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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