Reputation: 23
I'm using selenium to click on a button and the HTML code for the button is like:
div class="_1WZqU PNlAR" role="button">Join group</div
I tried with all possible solution:
driver.find_element_by_css_selector('._1WZqU.PNlAR').click()
driver.find_element_by_css_selector('_1WZqU PNlAR').click()
But its throwing an error no such element: Unable to locate element: {"method":"css selector","selector":"._1WZqU.PNlAR"}
Upvotes: 2
Views: 110
Reputation: 29362
You can try this code :
button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(text(),'Join group')]")))
button.click()
make sure you are importing :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Make sure element should not be in any frame/frameset/iframe.
If it is inside any frame , you have to switch the focus of your driver to that particular frame/iframe in order to interact with it.
Note : This is a div , the above code would work if and only if the div is clickable.
Upvotes: 1