Selenium Python จะตรวจสอบได้อย่างไรว่าตาราง html ไม่มีข้อมูล ตารางว่างเปล่า

ฉันมีตาราง HTML บนหน้าเว็บและตารางว่างเปล่า ไม่มีข้อมูลเนื่องจากข้อมูลถูกลบไปแล้วโดยการทดสอบครั้งก่อน สำหรับการทดสอบนี้ ฉันต้องการตรวจสอบ ตรวจสอบว่าตาราง html ว่างเปล่า แต่ไม่มีข้อมูล วิธีที่ดีที่สุดในการตรวจสอบสิ่งนี้คืออะไร? ฉันกำลังคิดที่จะใช้ Xpath ดังต่อไปนี้:

//table[@id="data_configuration_edit_data_object_tab_address_rules_tb_level_rules_locality"]//tr//td//div[text()=""]

ข้อมูลโค้ด HTML คือ:

<table id="data_configuration_edit_data_object_tab_address_rules_tb_level_rules_locality" class="GFNQNVHJE border" cellspacing="0" __gwtcellbasedwidgetimpldispatchingfocus="true" __gwtcellbasedwidgetimpldispatchingblur="true" style="min-width: 350px;">
<thead aria-hidden="false">
    <colgroup>
        <tbody style="display: none;"/>
        <tbody>
            <tr>
                <td align="center" colspan="2">
                    <div>
                        <div class="" style="width: 100%; height: 100%; padding: 0px; margin: 0px;" aria-hidden="false">
                            <div class="" style="width: 100%; height: 100%;" aria-hidden="false">
                                <div class="gwt-Label">No data to display.</div>
                            </div>
                        </div>
                        <div style="width: 100%; height: 100%; padding: 0px; margin: 0px; display: none;" aria-hidden="true">
                            <div class="GFNQNVHBE" style="width: 100%; height: 100%; display: none;" aria-hidden="true">
                                <div class="gwt-Label"></div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
        <tfoot style="display: none;" aria-hidden="true"/>
    </table>

ขอบคุณ Riaz


person Riaz Ladhani    schedule 30.09.2016    source แหล่งที่มา


คำตอบ (1)


สมมติว่าข้อความที่มองเห็นได้เพียงข้อความเดียวใน <table> เมื่อว่างเปล่าคือ "ไม่มีข้อมูลที่จะแสดง" จากนั้นคุณสามารถลดความซับซ้อนของ XPath ได้ดังต่อไปนี้ (จัดรูปแบบเพื่อให้อ่านง่าย):

//table[
    @id="data_configuration_edit_data_object_tab_address_rules_tb_level_rules_locality" 
        and 
    .='No data to display.'
]

xpatheval demo

person har07    schedule 30.09.2016
comment
ขอบคุณ ฉันจัดการเพื่อใช้ Xpath นี้ด้วย: //table[@id=data_configuration_edit_data_object_tab_address_rules_tb_level_rules_locality]//tr//td//div[contains(text(), No data to displays)] - person Riaz Ladhani; 30.09.2016