JavaScript语法错误:在Selenium Python中的参数列表之后缺少

2024-10-17 06:18:12 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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[]数组中

我怎样才能解决这个问题


Tags: 代码messagedatadriverselenium错误error数组
1条回答
网友
1楼 · 发布于 2024-10-17 06:18:12

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

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

相关问题 更多 >