python - 通过 XPath 选择 h2 元素

标签 python selenium

我需要通过 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)

关于python - 通过 XPath 选择 h2 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69103497/

相关文章:

python - RandomForestClassifier .fit 在 ec2 上因内存错误而失败,但在本地运行时没有错误

python - 这个 python 语法 dict(name=name) 是什么?

qt - Qt WebKit 应用程序的自动化 GUI 测试

python - 通过实现 __get__ 描述符编写瘦对象代理

java.lang.ClassCastException : class org. openqa.selenium.By$ByXPath 无法转换为类 org.openqa.selenium.WebElement

loops - 使用 Selenium 和 Robot Framework 遍历 Web 元素

java - 如何通过getText()从html内的多个子节点中提取动态文本

python - 更改多处理队列中的变量

python - [ :] work in python? 如何

python - Linux增加更多文本格式列的方法