<small id='Zdw5j'></small><noframes id='Zdw5j'>

    1. <i id='Zdw5j'><tr id='Zdw5j'><dt id='Zdw5j'><q id='Zdw5j'><span id='Zdw5j'><b id='Zdw5j'><form id='Zdw5j'><ins id='Zdw5j'></ins><ul id='Zdw5j'></ul><sub id='Zdw5j'></sub></form><legend id='Zdw5j'></legend><bdo id='Zdw5j'><pre id='Zdw5j'><center id='Zdw5j'></center></pre></bdo></b><th id='Zdw5j'></th></span></q></dt></tr></i><div id='Zdw5j'><tfoot id='Zdw5j'></tfoot><dl id='Zdw5j'><fieldset id='Zdw5j'></fieldset></dl></div>

        • <bdo id='Zdw5j'></bdo><ul id='Zdw5j'></ul>
        <legend id='Zdw5j'><style id='Zdw5j'><dir id='Zdw5j'><q id='Zdw5j'></q></dir></style></legend>
      1. <tfoot id='Zdw5j'></tfoot>

        使用 Selenium 和 CSS 查找阴影 DOM 文本

        时间:2023-09-06
        • <bdo id='0nfbY'></bdo><ul id='0nfbY'></ul>

          <tfoot id='0nfbY'></tfoot>

          <small id='0nfbY'></small><noframes id='0nfbY'>

            1. <legend id='0nfbY'><style id='0nfbY'><dir id='0nfbY'><q id='0nfbY'></q></dir></style></legend>
                <tbody id='0nfbY'></tbody>
                  <i id='0nfbY'><tr id='0nfbY'><dt id='0nfbY'><q id='0nfbY'><span id='0nfbY'><b id='0nfbY'><form id='0nfbY'><ins id='0nfbY'></ins><ul id='0nfbY'></ul><sub id='0nfbY'></sub></form><legend id='0nfbY'></legend><bdo id='0nfbY'><pre id='0nfbY'><center id='0nfbY'></center></pre></bdo></b><th id='0nfbY'></th></span></q></dt></tr></i><div id='0nfbY'><tfoot id='0nfbY'></tfoot><dl id='0nfbY'><fieldset id='0nfbY'></fieldset></dl></div>

                • 本文介绍了使用 Selenium 和 CSS 查找阴影 DOM 文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从保存在 shadow DOM 中的输入字段中查找输入文本:

                  I am trying to locate an input text from input field that is saved in shadow DOM with:

                  driver.find_element_by_css_selector("#my_id div:nth-of-type(2)").text 
                  

                  但这无济于事.HTML部分

                  but it does not help. HTML part

                  <input _ngcontent-c21="" class="clr-input ng-untouched ng-pristine ng-valid" id="my_id" name="my_id" placeholder="My placeholder namespace" size="40" type="text">
                   #shadow-root {user-agent}
                    <div pseudo="-webkit-input-placeholder" id="placeholder" style="display: none !important;">My placeholder namespace</div>
                    <div>Text I need to find</div>

                  运气不好也试过这个:

                  shadow_section = driver.execute_script('''return 
                  document.querySelector("#my_id").shadowRoot''')
                              print(shadow_section.find_element_by_css_selector("div:nth-of-type(2)").text)
                  

                  在这种情况下,在 shadow DOM 中查找元素的最佳方法是什么?在我的情况下,定位器应该链接到元素.

                  What is the best approach for finding elements in shadow DOM in this case? In my case locator should be linked to element.

                  更新:按照建议我尝试过:

                  Update: as suggested I tried:

                    shadow_root = driver.execute_script('return arguments[0].shadowRoot', driver.find_element_by_css_selector("#my_id"))
                    shadow_root_element = shadow_root(driver.find_element_by_css_selector('div:nth-child(2)'))
                  

                  但收到了:

                  TypeError: 'NoneType' object is not callable
                  

                  shadow_root_element 行上.

                  推荐答案

                  我无法找到使用 Javascripts .shadowRoot 选项的解决方案,为什么它不起作用对我来说是个谜.这个选项工作得很好.它输入文本:

                  I was not able to find a solution with Javascripts .shadowRoot option and it is a mystery for me why it does not work. This option works just fine. It input text:

                  driver.find_element_by_css_selector("#my_id").get_attribute("value")
                  

                  driver.find_element_by_id("my_id").get_attribute("value")
                  

                  我对PDHide提出的方法还是很感兴趣的.

                  I am still very interested in the approach proposed by PDHide.

                  这篇关于使用 Selenium 和 CSS 查找阴影 DOM 文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 testcafe 获取表格中所有单元格的文本 下一篇:Selenium:无法理解 xPath

                  相关文章

                  最新文章

                  <small id='tIAes'></small><noframes id='tIAes'>

                  <i id='tIAes'><tr id='tIAes'><dt id='tIAes'><q id='tIAes'><span id='tIAes'><b id='tIAes'><form id='tIAes'><ins id='tIAes'></ins><ul id='tIAes'></ul><sub id='tIAes'></sub></form><legend id='tIAes'></legend><bdo id='tIAes'><pre id='tIAes'><center id='tIAes'></center></pre></bdo></b><th id='tIAes'></th></span></q></dt></tr></i><div id='tIAes'><tfoot id='tIAes'></tfoot><dl id='tIAes'><fieldset id='tIAes'></fieldset></dl></div>
                  1. <legend id='tIAes'><style id='tIAes'><dir id='tIAes'><q id='tIAes'></q></dir></style></legend>
                      <bdo id='tIAes'></bdo><ul id='tIAes'></ul>

                    1. <tfoot id='tIAes'></tfoot>