[英]JavaScript SyntaxError: missing ) After Argument List in Selenium Python
I'm trying to execute JavaScript code in Python using selenium.我正在尝试使用 selenium 在 Python 中执行 JavaScript 代码。 But I'm getting the error down below:但我在下面得到错误:
selenium.common.exceptions.JavascriptException: Message: javascript error: missing ) after argument list
Here's my code:这是我的代码:
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)
Note: I'm getting array elements as an input from a GUI and then append them into data[]
array.注意:我从 GUI 获取数组元素作为输入,然后 append 将它们放入data[]
数组中。
How can I fix this?我怎样才能解决这个问题?
Add quotes around the data when the data is a string and not a variable (or int or float - but this wouldn't be a valid argument for window.open
anyway):当数据是字符串而不是变量(或 int 或 float - 但这不是window.open
的有效参数)时,在数据周围添加引号:
driver.execute_script(f"window.open('{data[0]}');")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.