首页 > 解决方案 > IE11 Script1003:应为“}”

问题描述

适用于 Chrome 和 Firefox,但 IE11 给我以下脚本错误。

IE11 Script1003: Expected "}" 请注意我正在从 selenium 执行脚本。例如:driver.execute_script("console.log(document.title)") 如果我犯了任何错误,你能告诉我怎么办。

标签: internet-explorer-11

解决方案


尝试用IE浏览器直接访问网站,用F12开发者工具查看是否有同样的错误?

根据您的代码,我假设您正在使用带有 IE webdriver 的 python,我使用以下代码创建了一个示例,该代码在 IE 11 浏览器中运行良好。

import time
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

cap = DesiredCapabilities().INTERNETEXPLORER
cap['ignoreZoomSetting'] = True
driver = webdriver.Ie("D:\\Downloads\\webdriver\\IEDriverServer_x64_3.14.0\\IEDriverServer.exe",capabilities= cap)


driver.get("https://www.bing.com")

time.sleep(5)

driver.execute_script("document.getElementById('sb_form_q').value = 'Hi webdriver'; console.log('hello webdriver');")

print("*******************")

请尝试测试上面的代码,如果仍然不能解决问题,请发布足够的代码来重现问题,如Minimal, Complete, and Verifiable example


推荐阅读