【发布时间】:2017-11-03 15:03:40
【问题描述】:
(使用 Python 3 和 Selenium。在按下“Shuffle”链接后尝试与 Buffer.com 的警报窗口进行交互。)
在主浏览器框架上按下一个按钮后,会弹出一个带有两个按钮的警报。我想按其中一个。
我正在尝试将焦点更改为包含警报的 iframe,但我看不到它有名称。这是所述警报 iframe 的代码:
<iframe src="https://js.stripe.com/v2/m/outer.html#referrer=https%3A%2F%2Fbuffer.com%2Fsignin&title=Buffer&url=https%3A%2F%2Fbuffer.com%2Fapp%2Fprofile%2F55e5cd556321154607cc5244%2Fbuffer%2Fqueue%2Flist&muid=c7aa769e-c41c-4e86-b75f-99771764f6a5&sid=26221bdc-c091-42c2-8965-8ea3e84267e2&preview=false&" frameborder="0" allowtransparency="true" scrolling="no" tabindex="-1" aria-hidden="true" style="width: 1px !important; height: 1px !important; position: fixed !important; visibility: hidden !important; pointer-events: none !important;"></iframe>
反过来,包含此 iframe 的元素有一个名称,但它是动态生成的。包含我想要的iframe的上层iframe的代码是:
<iframe name="stripeXDM_default441361_provider" id="stripeXDM_default441361_provider" aria-hidden="true" src="https://js.stripe.com/v2/channel.html?stripe_xdm_e=https%3A%2F%2Fbuffer.com&stripe_xdm_c=default441361&stripe_xdm_p=1#__stripe_transport__" frameborder="0" style="position: absolute; top: -2000px; left: 0px;"></iframe>
“stripeXDM_default441361_provider”是动态的,每次弹出警报时都会发生变化。
我尝试过 switch_to.frame 但无法正确处理。 我还尝试使用“包含 Xpath”选择动态生成的 iframe,但也没有工作。
关于如何选择这个没有名称的 iframe 有什么建议吗?
【问题讨论】:
标签: python-3.x selenium iframe