【问题标题】:How to select a specific element when it only appears when you hover your mouse over it? Selenium webdriver python;当您将鼠标悬停在特定元素上时如何选择它? Selenium webdriver python;
【发布时间】:2021-05-31 17:42:26
【问题描述】:

所以我要做的是从图像中显示的选择中按下 heartpulse 表情符号,selenium 已经可以通过使用它的 xpath 来执行此操作,但这仅在您将鼠标悬停在该区域上时才有效,作为预览当您移动鼠标时,所有表情符号都会消失。那么有没有一种方法可以选择心跳表情符号而无需手动将鼠标悬停在它上面?

到目前为止的代码: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

【问题讨论】:

  • 您的图片均未显示...请编辑您的问题并修复它们。
  • @JeffC 图像现已添加,不确定它们发生了什么。

标签: python selenium selenium-webdriver webdriver hover


【解决方案1】:

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

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-08
    • 2013-01-19
    • 2021-11-02
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    相关资源
    最近更新 更多