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

      • <bdo id='aDxbY'></bdo><ul id='aDxbY'></ul>
      1. <small id='aDxbY'></small><noframes id='aDxbY'>

        如何在 Selenium WebDriver 中获取单个文本节点

        时间:2023-10-12

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

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

                  本文介绍了如何在 Selenium WebDriver 中获取单个文本节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想从标签中获取文本,但没有嵌套标签中的文本.IE.在下面的示例中,我只想从 <small> 标记中获取字符串 183591 并排除文本 Service Request ID:来自 <span> 标签.这不是微不足道的,因为 <span> 标记嵌套在 <small> 标记中.这可以通过 WebDriver 和 XPath 实现吗?

                  I want to get the text from a tag but without the text from nested tags. I.e. in the example below, I only want to get the string 183591 from inside the <small> tag and exclude the text Service Request ID: from the <span> tag. This is not trivial because the <span> tag is nested in the <small> tag. Is this possible with WebDriver and XPath?

                  标签中的文字每次都会改变.

                  The text in the tag is going to change every time.

                  <div id="claimInfoBox" style="background-color: transparent;">
                  <div class="col-md-3 rhtCol">
                  <div class="cib h530 cntborder">
                  <h4 class="no-margin-bottom">
                  <p>
                  <small style="background-color: transparent;">
                  <span class="text-primary" style="background-color: transparent;">Service Request ID:</span>
                  183591
                  </small>
                  </p>
                  <div class="border-bottom" style="background-color: transparent;"></div>
                  <div id="CIB_PersonalInfo_DisplayMode" class="cib_block">
                  <div id="CIB_PersonalInfo_EditMode" class="cib_block" style="display: none">
                  </div>
                  </div>
                  <script type="text/javascript">
                  </div>
                  </div>
                  

                  推荐答案

                  您将不得不使用字符串操作.比如:

                  You are going to have to use String manipulation. Something like:

                  // you will need to adjust these XPaths to suit your needs
                  String outside = driver.findElement(By.xpath("//small")).getText();
                  String inside = driver.findElement(By.xpath("//span")).getText();
                  
                  String edge = outside.replace(inside, "");
                  

                  这篇关于如何在 Selenium WebDriver 中获取单个文本节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Selenium 中的 execute_script() 有什么作用 下一篇:什么是 JavaScript 垃圾回收?

                  相关文章

                  最新文章

                1. <small id='AxCXC'></small><noframes id='AxCXC'>

                  • <bdo id='AxCXC'></bdo><ul id='AxCXC'></ul>

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