How to click the below shown icon using Python Selenium?
Solution 1:
That's an SVG element, and I do see that the class svg-icon iconInbox
is unique in nature, so the below XPath should work for you.
//*[name()='svg' and @class='svg-icon iconInbox']
and using explicit wait, you can perform click like this:
wait = WebDriverWait(driver, 30)
try:
wait.until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg' and @class='svg-icon iconInbox']"))).click()
print('Clicked on the button')
except:
print('Could not click ')
pass
Imports:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Solution 2:
The selector for the Stack Overflow inbox is "svg.iconInbox"
.
You can verify that directly from the console with:
document.querySelector("svg.iconInbox")
Add that to a click method in a Selenium framework, and you can click it. Eg, here's how to click it using SeleniumBase:
self.click("svg.iconInbox")