雖然此信息無助於解決我的問題,但我會讓它知道我正在使用Selenium WebDriver在Python中創建自動化測試。查找具有相同地址位置的XPATH中的相同文本
我有一個問題,我想驗證兩個相同的文本元素,看起來有相同的XPATH地址的存在。正如你可以從下面的網頁的XPATH看到...
<div class="pagebox">
<h2>Database</h2>
Restrict access to group: <input id="database_group" name="database_group" value="postgres" type="text">
<br></br>
<h2>Sessions</h2>
User sessions time out after
<input id="session_timeout" name="session_timeout" maxlength="5" value="1200" type="text">
minutes.
<br></br>
<h2>HMI</h2>
<input id="use_large_header_text" name="use_large_header_text" type="checkbox">
Use large text in the header bar and link bar on HMI
<br></br>
<input id="display_tagging_button" name="display_tagging_button" checked="true" type="checkbox">
Display tagging button and information in HMI control dialog
<br></br>
<br></br>
<h2>Inactive Redirect</h2>
Auto redirect after user is inactive for
<input id="inactive_time" name="inactive_time" maxlength="4" placeholder="Min: 0 (Default) Max: 1440" size="25" value="0" type="text"></input>
minutes.
<span id="ieInactTime" style="font-style: italic"> Min: 0 (Default) Max: 1440</span>
<br></br>
Redirect Address:
<input id="inactive_page" name="inactive_page" placeholder="File Path e.g. /Home/" size="30" value="" type="text"><span id="ieInactPage" style="font-style: italic"> File Path e.g. /Home/</span>
<br></br>
...短語「分鐘」。顯示了兩次[第8行和第21行],但它沒有以我可以使用元素的XPATH定位我想驗證哪個元素的方式顯示,因爲我通常會使用您會發現的方法here,here或here。這兩個文本元素似乎有相同的確切地址XPATH:
//div[@class='pagebox']
我試着用括號來表示兩個文本元素之間的區分,我想驗證哪些文本元素...
e.g. //div[@class='pagebox']/[1] & //div[@class='pagebox']/[2]
...但沒有奏效。
我能找到的最接近的區分這兩種文本元素的方法是使用XPATH的'text()'特性。
//div[@class='pagebox']/text()[contains(.,'minutes')][1]
//div[@class='pagebox']/text()[contains(.,'minutes')][2]
有什麼方法可以用XPATH驗證這兩個文本元素嗎?
您可以在檢查器中將每個「分鐘」字符串重命名爲minutes_X。應該更容易找到你正在尋找的那個。 –
在您的示例代碼中,// // div [@ class ='pagebox']/input [2]'是「在HMI上的標題欄和鏈接欄中使用大文本」。使用'input [n]'是你如何區分它們。你在問什麼? – SiKing
@KevinS重命名「分鐘」。不幸的是,字符串不是一種選擇。這是我堅持不懈的方案,必須找到一種方法來實現它。 – rwbyrd