Selenium执行execute_script报unknown error: call function result missing 'value'求助
Hey there! I’ve run into this exact error before, so let’s break down how to fix it step by step.
First, let’s get to the root cause: your ChromeDriver version doesn’t match your Chrome browser version—this is the most common trigger for this error. Here’s what you need to do:
1. Match ChromeDriver to your Chrome version
Your Chrome is version 65.0.3325.162, but you’re using ChromeDriver 2.33—this is a clear mismatch. ChromeDriver 2.33 only supports Chrome versions 60-62. For Chrome 65, you need ChromeDriver 2.36 (it’s explicitly built to support Chrome 65-67).
- Download the correct ChromeDriver version for your Mac OS X system.
- Replace your existing chromedriver executable with the new one. Make sure your code points to the right path (or update your system PATH to include the new driver’s location).
2. Fix the execute_script syntax
Your current scroll code uses string formatting, which can sometimes cause unexpected issues with how the script executes. Instead of string concatenation, pass the scroll position as an argument to execute_script—this is the safer, recommended approach:
# Replace your current line with this driver.execute_script('window.scrollTo(0, arguments[0]);', scr)
This avoids potential syntax errors from direct string formatting and ensures the value is passed correctly to the JavaScript function.
3. Additional checks
- Make sure your Selenium library is up to date. Older versions might have compatibility issues with newer ChromeDriver releases.
- Restart your browser and test script—sometimes stale sessions or cached data can cause weird errors like this.
- Double-check that
scrholds a valid numeric value (not a string or undefined) before passing it to the scroll function.
Bonus note about the Send Keys error
Since you mentioned this error also popped up with Send Keys after upgrading ChromeDriver, fixing the version mismatch should resolve that issue too—most interaction errors in Selenium stem from driver-browser version incompatibility.
内容的提问来源于stack exchange,提问作者buzz11

