Selenium + Python:如何点击 Google Pay 弹出 iframe 结账上的“Pay”按钮?

问题描述 投票:0回答:2

更新:

这是结账链接。单击 gPay 按钮,使用 gPay 登录 Google 以查看最终的 Pay 按钮以完成我希望 Selenium 脚本单击的订单。

https://store.ui.com/14391668/checkouts/ae284ed7a99abc227e54933f1760e670


我有 Selenium 脚本来结账,然后单击 gPay 按钮,弹出一个窗口 iframe,下面有一个 Pay div 按钮。如何切换到iFrame并点击Pay按钮完成结账?

https://i.sstatic.net/pubLj.png

支付按钮div

<div role="button" class="goog-inline-block jfk-button jfk-button-action b3-button b3id-button b3-ripple-container b3-primary-button" tabindex="0" style="user-select: none;" data-start-event-id="-131" data-was-visible="true">Pay<div class="b3id-ripple b3-ripple" aria-hidden="true" data-was-visible="true"></div></div>

这是Body中的iframe

<iframe style="border: 0px none; vertical-align: initial; display: block; width: 100%; position: static; top: auto; visibility: visible; z-index: auto; background-color: inherit; height: 510px; left: auto; min-height: auto; opacity: 1; transition: all 0s ease 0s;" src="https://payments.google.com/payments/u/0/embedded/buy_flow?tc=98%2C97%2C81%2C83%2xxxxxxxxxxxx" id="**sM432dIframe**" name="sM432dIframe" data-widget="current" title="" frameborder="0"></iframe>

我已经尝试过这些但没有效果

WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.NAME, "sM432dIframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "goog-inline-block jfk-button jfk-button-action b3-button b3id-button b3-ripple-container b3-primary-button"))).click()

time.sleep(10)
driver.switch_to.frame("sM432dIframe")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "goog-inline-block jfk-button jfk-button-action b3-button b3id-button b3-ripple-container b3-primary-button"))).click()
python selenium iframe
2个回答
0
投票

switch_to.frame()
函数中,您需要指定包含 iframe 的元素。所以代替:

driver.switch_to.frame("sM432dIframe")

应该是:

iframe = driver.find_element(By.ID, 'sM432dIframe') 
driver.switch_to.frame(iframe)

0
投票

点击GPay,切换窗口,切换框架,点击

© www.soinside.com 2019 - 2024. All rights reserved.