2

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"}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.