[英]Access Input field of Stripe Payment using Playwright and C#
I m trying to access the id of the field of card number in stripe so i can input card number using c# and playwright.我正在尝试访问条带中卡号字段的 ID,以便我可以使用 c# 和 playwright 输入卡号。 i have a screenshot of the DOM and I tried the below code but in vain.我有 DOM 的屏幕截图,我尝试了下面的代码但没有成功。 could you please advise on how to access the card number ID?你能告诉我如何访问卡号ID吗?
var CardNumberLocator = Page.Locator("id=Field-numberInput");
await CardNumberLocator.FillAsync("1234123412341234");
This can be caused by multiple reasons;这可能是由多种原因引起的;
If it's embedded.如果嵌入的话。 You need to apply your logic to the Content Frame .您需要将逻辑应用于Content Frame 。
If it's invisible.如果看不见。 (maybe the focus is triggered through a div click and it's hidden with CSS even if it exists on the HTML), this might be the reason why it's not working because WaitForSelector/Locator waits for the element to be visible. (也许焦点是通过 div 单击触发的,即使它存在于 HTML 中,它也被 CSS 隐藏了),这可能是它不起作用的原因,因为 WaitForSelector/Locator 等待元素可见。 You can try using the page.$ selector, which will return the element whether or not it's invisible.您可以尝试使用page.$选择器,无论它是否不可见,它都会返回元素。
You can also trigger a page.click(div)
on the overlayed element [the div in this case], then use page.keyboard.type(text)
.您还可以在叠加元素 [本例中为 div] 上触发page.click(div)
,然后使用page.keyboard.type(text)
。 The simulated click will make the page focus on the input.模拟点击会让页面聚焦在输入上。 And the keyboard.type
will be typing into the input. keyboard.type
将在输入中输入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.