いくつかの行と列を持つHTMLテーブルがあります。値 "14"を持つ列3の行の値を取得できます ユーザーがGUIからレコードを削除すると、14がもう存在しないことを確認したいと思います。 私はエラーを取得する:値を見つけるためSelenium Python要素に値がないかチェックしたいNoSuchElementException:メッセージ:xpathで要素を見つけることができません
NoSuchElementException: Message: Unable to find element with xpath == //table[@id="reporting_view_report_dg_main_body"]//tr//td[3]/div/span[@title="14"]
私のXPATHです:
usn_id_element = self.get_element(By.XPATH, '//table[@id="reporting_view_report_dg_main_body"]//tr//td[3]/div/span[@title="14"]')
My機能ルーチン値をチェックするためには、
def is_usn_id_not_displayed_in_all_records_report_results(self, usn_id): # When a record has been disconnected call this method to check the record for usn id is not there anymore.
usn_id_element = self.get_element(By.XPATH, '//table[@id="reporting_view_report_dg_main_body"]//tr//td[3]/div/span[@title="14"]')
print "usn_id_element"
print usn_id_element
print usn_id_element.text
if usn_id not in usn_id_element:
return True
get_elementルーチンがありません:
from selenium.webdriver.common.by import By
# returns the element if found
def get_element(self, how, what):
# params how: By locator type
# params what: locator value
try:
element = self.driver.find_element(by=how, value=what)
except NoSuchElementException, e:
print what
print "Element not found "
print e
screenshot_name = how + what + get_datetime_now() # create screenshot name of the name of the element + locator + todays date time. This way the screenshot name will be unique and be able to save
self.save_screenshot(screenshot_name)
raise
return element
HTMLスニペットは:
<table id="reporting_view_report_dg_main_body" cellspacing="0" style="table-layout: fixed; width: 100%; margin-bottom: 17px;">
<colgroup>
<tbody>
<tr class="GFNQNVHJM" __gwt_subrow="0" __gwt_row="0"\>
<tr class="GFNQNVHIN" __gwt_subrow="0" __gwt_row="1"\>
<div __gwt_cell="cell-gwt-uid-9530" style="outline-style:none;">
<span title="14" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">14</span>
</div>
</td>
<td class="GFNQNVHIM GFNQNVHKM"\>
<td class="GFNQNVHIM GFNQNVHKM"\>
</tr>
<tr class="GFNQNVHIN" __gwt_subrow="0" __gwt_row="13">
<td class="GFNQNVHIM GFNQNVHJN GFNQNVHLM">
<td class="GFNQNVHIM GFNQNVHJN">
<td class="GFNQNVHIM GFNQNVHJN">
<div __gwt_cell="cell-gwt-uid-9530" style="outline-style:none;">
<span class="" title="14" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;display:block;padding-right: 1px;">14</span>
</div>
</td>
<td class="GFNQNVHIM GFNQNVHJN"\>
<td class="GFNQNVHIM GFNQNVHJN"\>
</tr>
<tr class="GFNQNVHJM" __gwt_subrow="0" __gwt_row="14"\>
<tr class="GFNQNVHIN" __gwt_subrow="0" __gwt_row="15"\>
</tbody>
</table>
値がないかどうかを確認するにはどうすればよいですか?
おかげで、リアズ
は、テーブル内の他のレコードがあります。 14はどの列にあってもよい。それが削除されたら私はチェックしたい14列3の行のいずれかのテーブルにない –
削除が発生した後、テーブル内の行はありません。行が削除されたようです。 –
ありがとうございました。数分でお知らせします –