3

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

但实际上它并没有看正确的元素。

4

2 回答 2

4

我尝试了以下方法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)
于 2021-09-08T13:01:39.947 回答
3

尝试:

//h2[@class="force--h4"]
于 2021-09-08T12:58:02.650 回答