当您将鼠标悬停在特定元素上时,该元素才会出现,如何选择该元素?Selenium-webdriver-python;

2024-04-23 07:39:05 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想做的是从图中所示的选择中按下heartpulse表情符号,selenium已经可以通过使用它的xpath来做到这一点,但这只在您将鼠标悬停在该区域上时起作用,因为当您移动鼠标时,所有表情符号的预览都会消失。那么,有没有一种方法可以选择heartpulse表情符号,而不必手动将鼠标悬停在其上

迄今为止的代码:heartpulse = driver.find_element_by_xpath("//*[@id="content"]/div/div[2]/div/div/div/div[1]/article/div/aside/ul/li[1]/div/div[2]/div/ul/li[5]/button/span/img") heartpulse.click()

同样,这只适用于将鼠标悬停在显示各种表情的区域上方时,否则它将不起任何作用

1

2

3

Link


1条回答
网友
1楼 · 发布于 2024-04-23 07:39:05

正如您所说,您必须首先将鼠标悬停在该元素上,然后单击心脏脉搏图标,如下所示。不要忘记延迟:)

from selenium.webdriver.common.action_chains import ActionChains


reactions_btns = driver.find_elements_by_xpath('//button[contains(@class,'Reactions')]')

hover = ActionChains(driver).move_to_element(reactions_btns[0])
hover.perform()

heart_pulses = driver.find_elements_by_xpath('//button[@title="heartpulse"]')
heart_pulses[0].click()

相关问题 更多 >