如何使用 Selenium 和 Python 单击#shadow-root(已关闭)内的按钮

发布于 2025-01-10 10:28:56 字数 929 浏览 0 评论 0 原文

我正在尝试单击 iframe 内的 #shadow-root (close) 内的按钮

<iframe title="recaptcha challenge expires in two minutes" 
   <div class="button-holder help-button-holder">
      #shadow-root (closed)
         <link rel="stylesheet" href="chrome-extension://mpbjkejclgfgadiemmefgebjfooflfhl/src/solve/solver-button.css">
         <button tabindex="0" title="Solve the challenge" id="solver-button"></button>
   </div>
</iframe>

这是我用来切换到 iframe 的按钮

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='recaptcha challenge expires in two minutes']")))

如何单击 //button[@id="solver -button"]

以下是 iframe 实际外观的照片

-链接

按钮-<一个href="https://i.sstatic.net/Zpyu3.jpg" rel="noreferrer">链接

I'm trying to click button inside #shadow-root (closed), inside iframe

<iframe title="recaptcha challenge expires in two minutes" 
   <div class="button-holder help-button-holder">
      #shadow-root (closed)
         <link rel="stylesheet" href="chrome-extension://mpbjkejclgfgadiemmefgebjfooflfhl/src/solve/solver-button.css">
         <button tabindex="0" title="Solve the challenge" id="solver-button"></button>
   </div>
</iframe>

This is what I use to switch to iframe

WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@title='recaptcha challenge expires in two minutes']")))

How can I click //button[@id="solver-button"]

Here are photos how it really looks

iframe-link

button-link

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

画骨成沙 2025-01-17 10:28:56

Your line of code to switch to the <iframe> was perfect. However, the desired element is within a #shadow-root (closed) and using Selenium you won't be able to interact with the elements within #shadow-root (closed) because as per the discussion in Shadow DOM traversal support:

  • @43081j mentioned, for closed shadow roots it should just be accepted that you can't access it (throw an exception). So, we don't need to care about closed roots as we shouldn't be able to access them anyway.
  • @AutomatedTester in his spec proposal suggested the ability to move between a Shadow DOM context and the document context.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文