selenium.common.exceptions.JavascriptException: Message: SyntaxError: unexpected token: identifier

初始:

string = ‘abc’

js = f"document.querySelector('body').innerText={string}"
driver.execute_script(js)

执行报错:

selenium.common.exceptions.JavascriptException: Message: SyntaxError: unexpected token: identifier

 

修改后:

string = ‘abc’

js = f"document.querySelector('body').innerText='{string}';"
driver.execute_script(js)

执行成功,原因是在输入的字符串没有加双引号,而且语句后没有带分号

上一篇:An unexpected error occurred: “https://registry.npm.taobao.org/animate.css: tunneling socket could n


下一篇:Vue3 + TS : Unexpected token,Did you mean `{‘}}` or `&rbrace`