繁体   English   中英

硒测试的XPath标识

[英]XPath identification for a Selenium Test

我是Selenium和XPath的新手。 您能帮我吗,我为以下结构正确识别了XPath:

<body>
<div id="body-wrapper">
<div id="outer-wrapper">
<div id="wrap2">
<div class="span-24">
<div style="clear: both;"/>
<div id="header-wrapper">
<div style="clear: both;"/>
<div class="span-24">
<div class="menu-secondary-container">
<ul class="menus menu-secondary">
<li>
<li>
<li class="">
<a class="sf-with-ul" href="#">
Automation
<span class="sf-sub-indicator">»</span>
<span class="sf-sub-indicator">»</span>
</a>
<ul class="children sub-menu" style="display: none; visibility: hidden;">
<li>
<a href="http://www.ufthelp.com/p/uft.html" title="UFT">UFT</a>
</li>

我已将XPath确定为:

("//div[@class='menutext']/descendant::ul[@class='children sub-menu']/a[@href='http://www.ufthelp.com/p/uft.html']"));

但是我NoSuchElementException 请同样帮我。 谢谢

您可以在firofox浏览器中使用firebug Extension轻松获得Xpath。 仅通过元素u选择即可获得xpath值。 FirePath是Firebug扩展,它添加了一个开发工具来编辑,检查和生成XPath。

  1. 类“菜单文本”丢失。
  2. 如果您的目标是锁定锚标记,那么我建议使用替代方法而不是xpath。 请试试

`

driver.findElement(By.tagName("a")) then(function(anchorTags) {
  anchorTags.getText().then(function(anchorText) {
    if (anchorText == UFT) {
      // do your thing here
    }
  })
})

`

XPATH:

// a [@ title ='UFT']

要么

// a [text()='UFT']

CSS:

a [title ='UFT']

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM