Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python selemium driver.execute_script()

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

JavascriptException: Message: javascript error: Unexpected identifier
(Session info: chrome=99.0.4844.82)

I don’t know why please help me.

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading