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

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

      1. Selenium:无法理解 xPath

        时间:2023-09-06

        <tfoot id='3r5zK'></tfoot>

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

              <small id='3r5zK'></small><noframes id='3r5zK'>

                  <tbody id='3r5zK'></tbody>
                  本文介绍了Selenium:无法理解 xPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一些这样的 HTML:

                  I have some HTML like this:

                  <h4 class="box_header clearfix">
                  <span>
                  <a rel="dialog" href="http://www.google.com/?q=word">Search</a>
                  </span>
                  <small>
                  <span>
                  <a rel="dialog" href="http://www.google.com/?q=word">Search</a>
                  </span>
                  </h4>
                  

                  我正在尝试使用 Selenium 在 Java 中获取 href.我尝试了以下方法:

                  I am trying to get the href here in Java using Selenium. I have tried the following:

                  selenium.getText("xpath=/descendant::h4[@class='box_header clearfix']/");
                  selenium.getAttribute("xpath=/descendant::h4[@class='box_header clearfix']/");
                  

                  但这些都不起作用.它一直抱怨我的 xpath 无效.谁能告诉我我做错了什么?

                  But none of these work. It keeps complaining that my xpath is invalid. Can someone tell me what mistake I am doing?

                  推荐答案

                  你应该使用getAttribute来获取链接的href.您的 XPath 需要对最终节点的引用以及所需的属性.以下应该有效:

                  You should use getAttribute to get the href of the link. Your XPath needs a reference to the final node, plus the required attribute. The following should work:

                  selenium.getAttribute("xpath=/descendant::h4[@class='box_header clearfix']/a@href");
                  

                  您还可以修改您的 XPath,使其更改更加灵活,甚至使用 CSS 来定位元素:

                  You could also modify your XPath so that it's a bit more flexible to change, or even use CSS to locate the element:

                  //modified xpath
                  selenium.getAttribute("//h4[contains(@class,'box_header')]/a@href");
                  
                  //css locator
                  selenium.getAttribute("css=.box_header a@href");
                  

                  这篇关于Selenium:无法理解 xPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 Selenium 和 CSS 查找阴影 DOM 文本 下一篇:将 Jest 与 Puppeteer 一起使用:评估失败:ReferenceErr

                  相关文章

                  最新文章

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

                    • <bdo id='qbfWB'></bdo><ul id='qbfWB'></ul>
                    <tfoot id='qbfWB'></tfoot>

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

                    1. <legend id='qbfWB'><style id='qbfWB'><dir id='qbfWB'><q id='qbfWB'></q></dir></style></legend>