Selenium Python bindings: how to execute JavaScript on an element? -
have used python selenium script trigger selenium server run javascript code. works fine.
drv.execute_script('<some js code>')
however, can't figure out how run javascript code on element retrieved using get_element_by_*() api. example,
ele = get_element_by_xpath('//button[@id="xyzw"]'); #question: how change "style" attribute of button element?
if on developer console of browser, can run
ele = $x('//button[@id="xyzw"]')[0] ele.setattribute("style", "color: yellow; border: 2px solid yellow;")
just don't know how in python selenium script. in advance.
execute_script
accepts arguments, can pass element:
drv.execute_script('arguments[0].setattribute("style", "color: yellow; border: 2px solid yellow;")', ele)
Comments
Post a Comment