2016-12-29 73 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']