如何编写 Selenium Xpath [英] How To Write Selenium Xpath

查看:27
本文介绍了如何编写 Selenium Xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在这里.我正在尝试为以下内容编写 Xpath.我正在尝试单击浏览".ID每次都在变化.

I am stuck here. I am trying a write Xpath for the following. I am trying to click "Browse". The ID is changing every time.

我已经试过这个作为我的 Xpath:

I have tried this as my Xpath:

//*[@id='ext-gen43']/em/span/span


<a id="ext-gen43" class="x-tab-right" href="#">
<em class="x-tab-left">
<span class="x-tab-strip-inner">
<span class="x-tab-strip-text ">Browse</span>
</span>
</em>
</a>

推荐答案

XPATH WRITING PLUGINS :

  • 为了自己编写xpath,您必须首先安装firebug和 firepath 插件,它们是 Firefox 可用的插件浏览器.
  • 您还可以安装 xpath checker,这是另一个可用于 Firefox 的插件.这是一个很棒的插件,因为你实际上可以在编写时查看 xpath 检查器中的 UI 元素xpath.
  • XPATH WRITING PLUGINS :

    • Inorder to write xpath's by yourself you must first install firebug and firepath plugins, they are the plugins available for Firefox browser.
    • You can also install xpath checker which is another plugin available for firefox. It's a awesome plugin because you can actually see the UI elements in the xpath checker as you are writing the xpath.
      • 为了自己编写 xpath,您必须遵循 firebug 中 HTML 选项卡中可用的子级和父级层次结构.
      • 将鼠标悬停在要编写 xpath 的元素上,以使用左上角萤火虫工具栏中可用的蓝色小箭头.

      • Hover on the element you want to write xpath for using the small blue arrow available in the firebug toolbar in the top left corner.

      现在单击该元素,您会看到萤火虫中相应元素的标记突出显示.

      Now click on the element, you would observe that the tag for the respective element in the firebug is highlighted.

      说你的标签看起来像:-

      Say your tag looks like :-

         <label> class="control-label col-sm-3" for="name"> Your Name <label>
      

      <小时>

      • 因此各个标签的 xpath 将是:-//label[@class="control-label col-sm-3"]
      • 所以上面的xpath指定了//parent标签是label,在括号中我们应该指定locator,locator可以是id,class,name什么的.

        在您的情况下,xpath 将是 :-

        //span[@class="x-tab-strip-text"]

        这篇关于如何编写 Selenium Xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆