Python 单击鼠标悬停时显示的元素

Python 单击鼠标悬停时显示的元素,python,selenium,Python,Selenium,我的情况是,有一个网格的元素和每个元素的悬停出现一个按钮,你可以点击然后。 查看class=“grid x0 y0”和class=“grid x1 y0”之间的差异id=“ccSelectDesignButton”仅在悬停时显示。我想点击第一个元素 我使用的代码是: temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']") hat= ActionCh

我的情况是,有一个网格的元素和每个元素的悬停出现一个按钮,你可以点击然后。

查看class=“grid x0 y0”class=“grid x1 y0”之间的差异id=“ccSelectDesignButton”仅在悬停时显示。我想点击第一个元素

我使用的代码是:

temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
hat= ActionChains(driver).move_to_element(temp).click()
time.sleep(10)
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
hat.click(button).perform()
但每次我遇到这个错误:

 Unable to locate element: {"method":"xpath","selector":"//a[@id='ccSelectDesignButton']"}

我也尝试了许多其他的方法来定位它,但仍然无法找到并单击它。有谁能给我一个更好的方法来处理这个问题吗?

我认为对于
鼠标悬停事件,您需要使用perform(),一旦完成,您可以选择desire button元素并单击它

temp = driver.find_element_by_xpath("//div[@id='gridContainer']//div[@class='grid x0 y0']")
ActionChains(driver).move_to_element(temp).perform()
time.sleep(2)
button = driver.find_element_by_xpath("//a[@id='ccSelectDesignButton']")
ActionChains(driver).move_to_element(button).click(button).perform()

如果您的查询未解决此问题,请共享此链接。

尝试使用javascript单击元素,如下所示:

driver.execute_script('$("a#ccSelectDesignButton").click();')