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)

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

posted on 2021-11-16 13:55  苦海舟  阅读(523)  评论(0)    收藏  举报

导航