首页 > 解决方案 > Selenium 中的 Web 表:使用条件从父元素访问子元素

问题描述

嗨,我想使用 Selenium 查找 web 表格元素,其中必须有一个特定的类,然后再搜索具有另一个特定类的行中的任何元素。

例如:

<tr class="slots tr_mrng">
                        <td colspan="2" style="background: rgb(237, 237, 237); height: 0px; border: none !important;">
                            <table class="slot-table" width="100%" style="border: none; display: none;">
                                <tbody><tr>
                                    <td id="15850908605e8209eda4133" class="reslabel" style="border:none !important;text-align:center;border-right:solid #36648B 1px !important" width="10%">
                                        07:01AM
                                    </td><td rowspan="1" class="unreservable slot"></td>
                                </tr>
                            </tbody></table>
                        </td>
                        <td colspan="2" style="background: rgb(237, 237, 237); height: 0px; border: none !important;">
                            <table class="slot-table" width="100%" style="border: none; display: none;">
                                <tbody><tr>
                                    <td id="15850908605e8209eda6554" class="reslabel" style="border:none !important;text-align:center;border-right:solid #36648B 1px !important" width="10%">
                                        07:01AM
                                    </td><td rowspan="1" class="unreservable slot"></td>
                                </tr>
                            </tbody></table>
                        </td>
                    </tr>

我想在“slots tr_mrng”类中找到“不可保留槽”类。不幸的是,我不知道如何使用 Selenium 处理条件。提前感谢您的帮助

标签: htmlselenium

解决方案


请尝试以下解决方案以使用 XPATH 在另一个表中处理 tr。另外,检查 iframe 下是否不存在表格。

//tr[@class='slots tr_mrng']//table[@class='slot-table']//td[@class='unreservable slot']]

推荐阅读