【问题标题】:JavaScript Syntax​Error: missing ) After Argument List in Selenium PythonJavaScript 语法错误:缺少)在 Selenium Python 中的参数列表之后
【发布时间】:2021-05-17 21:41:14
【问题描述】:

我正在尝试使用 selenium 在 Python 中执行 JavaScript 代码。但我在下面得到了错误:

selenium.common.exceptions.JavascriptException: Message: javascript error: missing ) after argument list

这是我的代码:

def selenium_process():
driver = webdriver.Chrome(data[3])
x = 0
driver.get(data[0])
while x <= postCount:
    driver.execute_script(f"window.open({data[0]});")
    x = x + 1
    if(x>postCount):
        time.sleep(10000000)

注意:我从 GUI 获取数组元素作为输入,然后将它们附加到 data[] 数组中。

我该如何解决这个问题?

【问题讨论】:

    标签: javascript python selenium


    【解决方案1】:

    当数据是字符串而不是变量(或 int 或 float - 但这不会是 window.open 的有效参数)时,在数据周围添加引号:

    driver.execute_script(f"window.open('{data[0]}');")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 1970-01-01
      • 2018-03-09
      • 2021-05-08
      相关资源
      最近更新 更多