selenium+python对页面元素进行高亮显示

调用js方法:

  execute_script(script,*args)

Arguments对象:

  类数组对象,代表传给一个function的参数列表,当前函数的内置属性,其长度是由实参个数决定而不是由形参个数决定

下面是高亮元素的函数:

def highlight(element):
driver = element._parent
#设置元素的style属性
def apply_style(s):
    将参数1:element的属性style设置为参数2:s
driver.execute_script("arguments[0].setAttribute('style', arguments[1]);",element, s)
  #获取元素原本的style
original_style = element.get_attribute('style')
  #执行高亮的js代码
apply_style("background: yellow; border: 2px solid red;")
time.sleep(3)
  #元素style还原
apply_style(original_style)
原文地址:https://www.cnblogs.com/quxikun/p/7388001.html