Selenium Python bindings: how to execute JavaScript on an element?

前端 未结 2 1045
予麋鹿
予麋鹿 2021-01-12 01:46

Have used python selenium script to trigger selenium server to run JavaScript code. It works fine.

drv.execute_script(\'\')
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 02:18

    execute_script accepts arguments, so you can pass the element:

    drv.execute_script('arguments[0].setAttribute("style", "color: yellow; border: 2px solid yellow;")', ele)
    

提交回复
热议问题