参数列表后的Python:JavaScript错误:缺少)

时间:2019-12-07 00:01:22

标签: javascript python selenium

在下面运行python脚本时,出现一条错误消息“参数列表后缺少javascript错误:missing”。该脚本在“ driver.execute_script(tab)”处失败。我已经尝试过对其进行调整,但无法解决。

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)

2 个答案:

答案 0 :(得分:2)

您可以完全避免引用:

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

答案 1 :(得分:0)

在网址周围添加引号。

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