I'm really tired of the stupid library selenium. If you want to pass js code to Selenium, use:
`js = "JS code here"
driver.excute_script(js)`
However, my js code has multiple lines, which looks like below:
setTimeout(function(){
l = document.getElementsByClassName("test-option");
for(const a in l){if(l[a]==undefined || l[a]==null)
continue
if(l[a].innerText !=undefined && l[a].innerText.includes("Miracle"))
{
l[a].click();
}
}
}, 2000);
When you delete the new line char in each line and put them together with single or double quotes. Selenim starts to spark. Is there any better way to pass the js string? Thanks
Aside from being messy that shouldn't be a problem:
driver.execute_script("""
setTimeout(function(){
l = document.getElementsByClassName("test-option");
for(const a in l){if(l[a]==undefined || l[a]==null)
continue
if(l[a].innerText !=undefined && l[a].innerText.includes("Miracle"))
{
l[a].click();
}
}
}, 2000)
""")