问题
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