In generally, if the javascript snippet can work in browser console, it should be also work in execute_script(). The only possiblility can lead failure is the arguments we passed down javascript snippet from program script side.
Let's take following example to explain, suspect we want to change the value of inputbox, we can use execuite_script() as below to archive that:
inputEle = driver.find_element_by_xxxx('css/xpath locator')
newValue = '';
driver.execute_script('arguments[0].value=arguments[1]', inputEle, newValue)
In above example, there are two arguments passed down to javascript snippet from program script side:
1) inputEle will replace the placehold: arguments[0]
2) newValue will replace the placehold: arguemnts[1]
Only when not find the element inputEle, the execute_script() will fail. Once you make sure the arguments[0].value=arguments[1] is a correct javascript code snippet in browser, there is no other factor will cause execute_script() fail.
And we can using following manual steps to confirm the execute_script() can archive the effect we wanted or not before execute it:
Verify the css/xpath locator in browser DevTool Element Tab
As below picture shows, the matched element HTML code will be highlight with yellow background, then mouse over on the HTML code, the corresponding element on page will be highlight, until now we can confirm the css/xpath locator can find element we want or not.

Verify javascript snippet in browser DevTool Console Tab
a) Select the HTML node of the element then switch to Console Tab
b) Type $0 and press Enter, it will print out the HTML code of selected element
c) Double check the output HTML is same as the selected element
d) Type $0.value= and press Enter
e) Back to the page to check any changes on page and it's you wanted.
(In Chrome DevTool, $0 represent the selected HTML node in Element Tab)
