最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to open closed shadow root in a iframe using selenium in Python? - Stack Overflow

programmeradmin5浏览0评论

I noticed there are only questions like how to access iframe inside a shadow dom, that can not solve my problem i think...

So the target page is like this(normal Cloudflare human verification that you can see everywhere):

<div>
  #shadow-root (closed) <!--(1)-->
  <iframe>
    #shadow-root (closed) <!--(2)-->
  </iframe>
</div>

I used selenium's cdp js evaluation work around the (1) #shadow-root, but the cdp just don't work for the (2) one, my python code:

def inject_shadow_open():
    driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {'source': """
   if (!Element.prototype.__attachShadow) {
            Element.prototype.__attachShadow = Element.prototype.attachShadow;
            Element.prototype.attachShadow = function(config) {
                return this.__attachShadow({ ...config, mode: "open" });
            };
        }
    """})
    driver.execute_script("""
    try {
        delete Element.prototype.attachShadow;
        Element.prototype.attachShadow = function(config) {
            return this.__attachShadow({ ...config, mode: "open" });
        };
    } catch(e) { console.log('Injection already exists') }
    """)

What should I do next?

发布评论

评论列表(0)

  1. 暂无评论