Selenium 点击的视觉反馈

Visual feedback for Selenium clicks

我将 Selenium (Python) 与 Firefox webdriver 结合使用来抓取网站。在浏览网站时,我想实际查看点击的位置。单击后出现 0.5 秒的类似圆圈的东西。

也欢迎其他语言 (Java) 的回答。只要是硒就可以了。

有人有这方面的经验吗?

点击DOM个元素即可使用该功能

def change_style(elem, driver, new_style):
    driver.execute_script("arguments[0].{} = arguments[1]".format('style'), elem, new_style)

然后像这样调用这个函数:

elem = driver.find_element... #your code to get the element
old_style = elem.get_attribute('style') #save the original style before you change it
highlight_style = "background: yellow; border: 2px solid red;" #change the bg of element to yellow and add a red border to it
change_style(elem, driver, highlight_style)
...
#your code to click the element, and when clicking next item you can change the last item back to its original style
change_style(elem, driver, old_style)

所以在两次点击之间,您可以看到最后点击的突出显示的网络元素。希望对你有帮助。