-1

This is the HTML syntax but I want to locate the element using value "ADD QUERY" using find_element_by_css_selector.

Image of HTML: Image HTML

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ravi
  • 1
  • 1

1 Answers1

0

To locate the element you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = driver.find_element(By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")
    
  • Using XPATH:

    element = driver.find_element(By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")
    

Ideally, to locate the element you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.global-button-primary.telemetry-button")))
    
  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class, 'global-button-primary') and contains(@class, 'telemetry-button')][contains(., 'ADD QUERY')]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352