I want to cancel all checkbox one time. Use element.click() is ugly but it can work like this
allcan=driver.find_elements(By.XPATH,'//*[@type="checkbox"]')
for i in allcan:
i.click()
So I try to use driver.execute_script() like this
allcan = 'var index = form1.no.value; \
for (i=1;i<=index;i ){ \
var rchk = document.getElementsByName("del_Y" i)[0] \
rchk.checked = false \
;}'
driver.execute_script(allcan)
That JavaScript can work in chrome console,but in python it show me
JavascriptException: Message: javascript error: Unexpected identifier
(Session info: chrome=99.0.4844.82)
I don't know why please help me.
CodePudding user response:
You need to end this statement with semicolon.
var rchk = document.getElementsByName("del_Y" i)[0];
This will get rid of SyntaxError
, but as @Peterrabbit mentioned in the comment you need to pay attension to i
and form1
as those variables are not defined. So most likely you will encounter with Reference Error
.