English 中文(简体)
如何利用javascript在影子内选择ton子
原标题:How to use javascript to select the button inside a shadow root
  • 时间:2023-07-03 02:31:29
  •  标签:
  • javascript

I am curious to see how this situation can be solved. In browser, I am seeing the following content (note the button is in highlight) enter image description here However, the selected the shadow root document.querySelector("ow-356ai793a").shadowRoot lost the entire content within the div element <div shell-wrapper="" data-spot-im-direction="ltr"></div>, as shown here enter image description here

• 我如何选择丁顿的“代码”和带;丁顿的作用=“丁顿”数据-编号=“show-more”数据-spot-im-class=“load-more-messages” aria-label=“Show more comments”数据- openweb-allow-amp=“true”类型=“Button__button-11-4-6 Button_first-11-4-64-6 Button__isEllipsis-11-4-6 Button__hoverBackground-11-4-6spicv_load-more-messages”><span category=“Button__contentWrapper-11-4-6”><span>Show More comment</span></span></button> in the soil?

问题回答

你可以尝试:

const shadowRoot = document.querySelector("ow-356ai793a").shadowRoot;
const observer = new MutationObserver((mutations) => {
  for (const mutation of mutations) {
    if (mutation.addedNodes.length > 0) {
      for (const node of mutation.addedNodes) {
        if (node.matches("button[role= button ]")) {
          console.log(node);
          observer.disconnect();
        }
      }
    }
  }
});

observer.observe(shadowRoot, { childList: true });

然而,这种方法在任何情况下都不能奏效,因为它取决于如何和何时创建纽扣元素并附在影子后。 如果不适当使用,也可能造成业绩问题或记忆泄露。 因此,我建议使用一个图书馆或框架,为等待出现诸如Cypress、Selenium、Pppeteer等内容提供方法或选择。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签