Complete the code to change the 'value' attribute of an input element using JavaScript.
driver.execute_script("arguments[0].setAttribute('value', [1])", element)
The JavaScript code requires the new value as a string literal, so it must be enclosed in quotes inside the script string. Option A correctly provides a quoted string.
Complete the code to remove the 'disabled' attribute from a button element using JavaScript.
driver.execute_script("arguments[0].[1]('disabled')", button)
To remove an attribute in JavaScript, use removeAttribute. This deletes the attribute from the element.
Fix the error in the code to correctly change the 'class' attribute of an element using JavaScript.
driver.execute_script("arguments[0].setAttribute('class', [1])", elem)
The value passed to setAttribute must be a JavaScript string literal, so it needs quotes inside the script string. Option A correctly provides a quoted string.
Fill both blanks to set the 'title' attribute of an element to 'Hello World' using JavaScript.
driver.execute_script("arguments[0].[1]([2], 'Hello World')", elem)
The method to set an attribute is setAttribute and the attribute name must be the string 'title'.
Fill all three blanks to toggle the 'hidden' attribute on an element using JavaScript.
driver.execute_script("if (arguments[0].hasAttribute([1])) { arguments[0].[2]([3]); } else { arguments[0].setAttribute([1], '') }", elem)
To toggle the 'hidden' attribute, first check if it exists with hasAttribute('hidden'). If it does, remove it with removeAttribute('hidden'). Otherwise, set it with setAttribute('hidden', ''). The blanks correspond to these strings and method names.