Home > Software design >  Selenium Python find element by CLASS_NAME returns CSS_SELECTOR not found
Selenium Python find element by CLASS_NAME returns CSS_SELECTOR not found

Time:07-04

Trying to click on this element in Selenium / Python:

<svg width="40" height="40" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg" ></svg>

My code:

WebDriverWait(driver,5,.25).until(EC.presence_of_element_located((By.CLASS_NAME,"bi bi-x-circle")))

driver.find_element(By.CLASS_NAME,"bi bi-x-circle").click()

The error:

Message: no such element: Unable to locate element: {"method":"css selector","selector":".bi bi-x-circle"}

I can make this work by xpath, but I'm wondering why this says it can't find a css selector when I'm searching for a class. I'd rather deal with class names just because they're easier to read. The element itself is an X in the corner of a popup, if that matters.

CodePudding user response:

Try:

WebDriverWait(driver,15).until(EC.element_to_be_clickable((By.CSS_SELECTOR,".bi.bi-x-circle"))).click()
#OR
driver.find_element(By.CSS_SELECTOR,".bi.bi-x-circle").click()
time.sleep(1)
  • Related