Issue
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" class="bi bi-x-circle"></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.
Solution
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)
Answered By - F.Hoque
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.