Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting h2 element via XPath

I would need to access this element via 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

I tried with

wait.until(EC.visibility_of_element_located((By.XPATH, "//h2[text()='Sorry, xxx could not be found or reached (error code 404)']")))

But actually it does not look at the right element.

like image 758
LdM Avatar asked Aug 05 '26 02:08

LdM


1 Answers

I tried the below CSS_SELECTOR :

section.section div.container h2

with explicit waits like :

h_ele = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "section.section div.container h2")))
print(h_ele.text)
like image 145
cruisepandey Avatar answered Aug 07 '26 17:08

cruisepandey