2016-12-29 70 views
0

我是Selenium和XPath的新手。你能帮帮我,我正确识别的XPath的结构如下:Selenium测试的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。请帮助我一样。谢谢

+0

我觉得这将帮助您轻松找到他们和学习http://stackoverflow.com/questions/3030487/is-there-a-你得到的HTML是不正确的 – Garfield

+0

尝试这个'/ * * [@ id =“header-wrapper”]/div/div/div/UL /锂[3]/UL/LI/A' – sandyJoshi

回答

0

U可以很容易地使用firbox浏览器中的萤火虫扩展Xpath。只要选择元素u就可以得到xpath值。 FirePath是一个Firebug扩展,增加了一个开发工具来编辑,检查和生成XPath。

0
  1. “menutext”类缺失。
  2. 如果你的目标是锁定锚标记,那么我会建议一个备用而不是xpath。请尝试

`

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

`

0

XPATH:

//一个[@标题= 'UFT']

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

CSS:

一个[标题= 'UFT']