python - 通过 XPath 选择 h2 元素
问题描述
我需要通过 XPath 访问这个元素:
<section class="section">
<div class="help-info">
<div class="container">
<div class="tile tile--bottom">
<h2 class="force--h4">Sorry, xxx could not be found or reached (error code 404) </h2> ==$0
我试过了
wait.until(EC.visibility_of_element_located((By.XPATH, "//h2[text()='Sorry, xxx could not be found or reached (error code 404)']")))
但实际上它并没有看正确的元素。
解决方案
我尝试了以下方法CSS_SELECTOR
:
section.section div.container h2
有明确的等待,如:
h_ele = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "section.section div.container h2")))
print(h_ele.text)
推荐阅读
- c# - 使用 MVVM 模式关闭打开的窗口,产生 System.NullReferenceException 错误
- node.js - 如何在nodejs中通过shell运行时等待异步函数
- reactjs - 模块别名无法解析为玩笑(CRA 和 custom-cra)
- kubernetes - Calico 从所有节点通告所有 Kubernetes 节点子网
- python - 如何找到在每次迭代中获得的最大值以将其附加到列表中
- java - Swing 中的 Ctrl + ~ 热键
- python - 如何从 ONNX 模型中获取输入数据?
- windows - 我们可以在一台机器上从 cmake 制作解决方案文件并在另一台机器上运行吗?
- c# - 重新定义一个类或函数
- vba - 您如何转到从列表框中选择并显示在导航表单上的特定记录?