Python: javascript error: missing ) after argument list [duplicate]

只愿长相守 提交于 2021-01-29 08:45:07

问题


When running the python script below I'm getting an error message "javascript error: missing ) after argument list". The script is failing at "driver.execute_script(tab)". I've tried adjusting it but I'm not able to solve it.

import selenium
from selenium import webdriver

driver = webdriver.Chrome()

driver.get('http://techstepacademy.com/training-ground')

list = ['http://yahoo.com', 'http://google.com','http://techstepacademy.com/training-ground']

for url in list:
    tab = "window.open(" + url + ",'_blank')"
    driver.execute_script(tab)

回答1:


You can avoid those quotes completely:

driver.execute_script("window.open(arguments[0])", url)



回答2:


add quotes around url.

 tab = "window.open(" + '"' + url + '"' + ",'_blank')"


来源:https://stackoverflow.com/questions/59221808/python-javascript-error-missing-after-argument-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!