![](/img/trans.png)
[英]Selenium WebDriver C# not find element by FindElement(by.xpath)
[英]Find element with xpath in c# selenium webdriver
我的源代碼中有這個元素,我得到帶有內部text(yahoo)的h2元素,並且我想訪問包含h2的最近文章。
<article>
<div></div>
<div></div>
<header>
<a></a>
<a>
<h2>yahoo</h2>
</a>
</header>
</article>
我寫的XPath是這樣的: //h2[text()='yahoo']//..//..
但它不起作用。
這個xpath怎么樣:
//h2[. = 'yahoo']/ancestor::article[1]
獲得包含<h2>
元素的<article>
元素的一種可能的XPath等於yahoo
:
//article[.//h2='yahoo']
如果您想與文章打交道,請使用下一個字符串:
//article[header//h2[text='yahoo']]
請使用此xpath並嘗試: //h2[text()='yahoo']//..//..//..
說明:
1st //..
帶您進入anchor(a)標簽。
第二個//..
帶您進入標頭標記。
3rd //..
將帶您到達想要的位置,即商品標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.