html - 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 处理条件。提前感谢您的帮助
解决方案
请尝试以下解决方案以使用 XPATH 在另一个表中处理 tr。另外,检查 iframe 下是否不存在表格。
//tr[@class='slots tr_mrng']//table[@class='slot-table']//td[@class='unreservable slot']]
推荐阅读
- regex - Lua gsub - 如何在正则表达式模式中设置最大字符限制
- wso2 - WSO2 APIM 分析:如何在 WSO2AM_STATS_DB 中捕获秒数
- class - 如何在 C++ 中显示使用对象引用调用的函数的结果
- common-lisp - 在 Common Lisp 中使用可变数据作为哈希表键?
- android - 错误:程序类型已存在:com.google.android.gms.internal.measurement.zzdz 添加分析后
- python - 在 Python 下使用套接字时,“每个套接字地址通常只允许一次使用”告诉我什么?
- android-studio - 字符串索引越界导致构建未完成
- node.js - 在 Azure 应用服务上安装 python——我可以使用哪些工具?
- javascript - JS 切换不扩展 div
- javascript - Firebase 函数 - http 获取带有强调的参数