我的頁面有一個11列的表,給定了第2列的文本值,我想單擊同一行的第11列(箭頭按鈕)。找到與td的xth td包含在相同的tr xpath中python
我的DOM看起來是這樣的:
<table id=」atab」 width=」100%」 class=」at-class」>`
<thead>…</thead>
<tbody>
<tr>...</tr>
<tr>
<td>…</td>
<td>
<a href=」/abc/def/ghi/prop?id=1」>grp1</a>
</td>
<td>…</td>
<td>…</td>
<td>200</td>
<td>…</td>
<td>…</td>
<td>…</td>
<td>…</td>
<td>…</td>
<td>
<ul class=」dropwd」
<li class>
<input class=」a-act a-menu-button」 type=」button」 value=」^」
<ul class=」sub_menu」 style=」vis」」>…</ul>
</li>
</ul>
</td>
<tr>
<tbody>
這工作(我只是抓住了從檢查元素中的XPath)。我不能使用它。
myxpath = "//*[@id='atab']/tbody/tr[2]/td[11]/ul/li/input」
myxpath.click()
我需要使用包含,然後抓住兄弟姐妹(第11位,第9從我有我的包含)。我嘗試了以下for mypath,但它找不到該元素。我在其他地方使用過相同的格式,並沒有問題。唯一的區別是這一次,我沒有得到鄰居兄弟姐妹,而是第x兄弟姐妹。
WHERE campg = grp1
//table[@class='at-class']//td[contains(text(),' " + campg + " ')]/following-sibling::td[9]/ul/li/input
//* [@id='atab']//td[contains(text(),' " + campg + " ')]/following-sibling::td[9]/ul/li/input
//* [@id='campaigns']//td[contains(text(),' " + campg + " ')]/following-sibling::td[9]/ul/li/input[@type=’button’]
我嘗試過其他的組合了。
我也會用'follow-sibling'來做。我想知道你的問題不是來自單引號和雙引號之間的空格......「+ + campg +」'...'。你也可以在按鈕的值上使用謂詞嗎? (以便不需要知道包含你的按鈕的td的extact位置)。就像這樣:''// table [@ class ='at-class'] // td [contains(。,'「+ campg +」')]/following-sibling :: td // ul/li/input [@ type ='button'and @value ='^']「' –
另一件事,使用'%'語法創建XPath表達式通常更具可讀性:'」// table [@ class ='at-class '] // td [contains(。,'%s')]/following-sibling :: td // ul/li/input [@ type ='button'and @value ='^']「%campg' –
我嘗試了你所說的話,但仍然無法找到該元素。空間不是問題(這是一個錯字,我沒有空格)。我還試着用謂語,仍然沒有運氣。下面的第二個答案完美地工作。謝謝你們一起研究它。 –