按钮操作在selenium python中不起作用

按钮操作在selenium python中不起作用,python,html,selenium,css-selectors,selenium-chromedriver,Python,Html,Selenium,Css Selectors,Selenium Chromedriver,我使用selenium单击按钮,按钮的HTML代码如下: div class="_1WZqU PNlAR" role="button">Join group</div 但是它抛出了一个错误:没有这样的元素:无法定位元素:{“method”:“css selector”,“selector”:“{u 1WZqU.PNlAR”}您可以尝试以下代码: button = WebDriverWait(driver, 20).until(EC.element_to_be_clicka

我使用selenium单击按钮,按钮的HTML代码如下:

 div class="_1WZqU PNlAR" role="button">Join group</div

但是它抛出了一个错误:没有这样的元素:无法定位元素:
{“method”:“css selector”,“selector”:“{u 1WZqU.PNlAR”}
您可以尝试以下代码:

  button =   WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(text(),'Join group')]")))  
  button.click()  
确保您正在导入:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC  
确保元素不应位于任何帧/帧集/iframe中

如果它在任何帧内,您必须将驱动程序的焦点切换到该特定帧/iframe,以便与之交互

注意:这是一个div,当且仅当该div可点击时,上述代码才有效。

工作起来很有魅力:)谢谢@cruisepandey
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC