![](/img/trans.png)
[英]C# Selenium WebDriver - How to get pure text with FindElement.(By.XPath).Text
[英]Selenium WebDriver C# not find element by FindElement(by.xpath)
我正在嘗試在下表中找到元素<td>!!mmm region test !!mmm region test</td>
。
...
<div class="panel-body cim-padding-zero">
<div class="row">
<div class="col-md-12">
<section id="UserListArea">
<div class="jtable-main-container">
...
<table class="jtable">
...
<tbody>
<tr class="jtable-data-row jtable-row-even Pointer" data-record-key="88">
<td></td>
</tr>
<tr class="jtable-data-row Pointer" data-record-key="301">
<td></td>
</tr>
<tr class="jtable-data-row jtable-row-even Pointer" data-record-key="302">
<td></td>
</tr>
<tr class="jtable-data-row Pointer" data-record-key="524">
<td></td>
</tr>
<tr class="jtable-data-row jtable-row-even Pointer jtable-row-selected" data-record-key="651">
<td>!!mmm region test !!mmm region test</td>
</tr>
...
</tbody>
</table>
...
我已經試過了
IWebElement UserList = driver.FindElement(By.XPath("//section[@id='UserListArea']/div/table/tbody/tr[5]/td"));
和這個
IWebElement UserList = driver.FindElement(By.XPath("//*[@id='UserListArea']/div/table/tbody/tr[5]/td"));
但在每種情況下我都會得到錯誤
OpenQA.Selenium.NoSuchElementException:無法找到元素:{“ method”:“ xpath”,“ selector”:“ // section [@ id ='UserListArea'] / div / table / tbody / tr [5] / td” }
您可以在Xpath下嘗試:
//*[@id='UserListArea']/div/table/tbody/tr[5]/td[contains(.,'!!mmm region test !!mmm region test')]
要么
//*[@id='UserListArea']//tr[@data-record-key='651']/td
要么
//tr[@class='jtable-data-row jtable-row-even Pointer jtable-row-selected']/td
如果仍然顯示硒,則顯示NoSuchElementException
然后檢查是否存在任何幀。 如果有框架,那么您需要先切換到框架
請下次再正確編輯您的HTML。 讀起來很不舒服
//tr[@data-record-key="651"]/td
這對我行得通
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.