python - How to set the id attribute of a WebElement? -


according selenium api doc, there function getattribute there no setattribute

ideally able following:

element.set_attribute('id', 'abcd') 

what want achieve set id of webelement during test.

i using driver 2.44 , not support execute_script argument

you cannot set attribute of element using selenium. primarily, automating web applications testing purposes.

selenium allow executing javascript on web page though.

see below examples:

you can execute arbitrary javascript find element , long return dom element, automatically converted webelement object.

webelement element = (webelement) ((javascriptexecutor)driver).executescript("return $('.cheese')[0]"); 

finding input elements every label on page:

list<webelement> labels = driver.findelements(by.tagname("label")); list<webelement> inputs = (list<webelement>) ((javascriptexecutor)driver).executescript(     "var labels = arguments[0], inputs = []; (var i=0; < labels.length; i++){" +     "inputs.push(document.getelementbyid(labels[i].getattribute('for'))); } return inputs;", labels); 

for more information, can go through selenium documentation , precise.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -