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:
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:
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