我是Selenium和XPath的新手。能帮到我吗?我为以下结构正确识别了XPath:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$('.cloneitem').not('.cloned').clone().addClass('cloned').appendTo('body');
});
});
</script>
</head>
<body>
<p class="cloneitem">This is a paragraph.</p>
<button>Clone all p elements, and append them to the body element</button>
</body>
</html>
我已将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>
但是我遇到了("//div[@class='menutext']/descendant::ul[@class='children sub-menu']/a[@href='http://www.ufthelp.com/p/uft.html']"));
。请帮我一样。感谢
答案 0 :(得分:0)
你可以在firofox浏览器中使用firebug Extension轻松获得Xpath。只需通过元素u选择即可获得xpath值。 FirePath是一个Firebug扩展,它添加了一个开发工具来编辑,检查和生成XPath。
答案 1 :(得分:0)
`
driver.findElement(By.tagName("a")) then(function(anchorTags) {
anchorTags.getText().then(function(anchorText) {
if (anchorText == UFT) {
// do your thing here
}
})
})
`
答案 2 :(得分:0)
XPATH:
// a [@title =&#39; UFT&#39;]
或
//一个[文本()=&#39; UFT&#39;]
CSS:
a [title =&#39; UFT&#39;]