英文:
Python Selenium Webdriver JSON.stringify is not a function
问题
**Selenium and Chrome verions:**
import selenium
selenium.__version__
'4.10.0'
Chrome Version: 114.0.5735.91 (Official Build) (64-bit)
**This code used to work for me just fine:**
```python
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
My_Link = "......"
DRIVER_PATH = 'I://Decoded//chromedriver.exe'
s=Service(DRIVER_PATH)
browser = webdriver.Chrome(service=s)
browser.get(My_Link)
browser.find_element(By.NAME,"USER").send_keys(r)
browser.find_element(By.NAME,"PASSWORD").send_keys(d)
browser.find_element(By.CSS_SELECTOR,".ButtonSm").click()
cookies= browser.get_cookies()
It's now giving me this error:
WebDriverException Traceback (most recent call last)
<ipython-input-10-b6bb484d2c6a> in <module>
1
2
----> 3 cookies= browser.get_cookies()
WebDriverException: Message: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function
at buildError (<anonymous>:323:18)
(Session info: chrome=114.0.5735.91)
Stacktrace:
Backtrace:
GetHandleVerifier [0x010CA813+48355]
(No symbol) [0x0105C4B1]
Any idea what is causing this exception pls ?
I tried microsoft edge, same issue.
<details>
<summary>英文:</summary>
**Selenium and Chrome verions:**
import selenium
selenium.__version__
'4.10.0'
Chrome Version: 114.0.5735.91 (Official Build) (64-bit)
**This code used to work for me just fine:**
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
My_Link = "......"
DRIVER_PATH = 'I://Decoded//chromedriver.exe'
s=Service(DRIVER_PATH)
browser = webdriver.Chrome(service=s)
browser.get(My_Link)
browser.find_element(By.NAME,"USER").send_keys(r)
browser.find_element(By.NAME,"PASSWORD").send_keys(d)
browser.find_element(By.CSS_SELECTOR,".ButtonSm").click()
cookies= browser.get_cookies()
**It's now giving me this error:**
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-10-b6bb484d2c6a> in <module>
1
2
----> 3 cookies= browser.get_cookies()
WebDriverException: Message: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function
at buildError (<anonymous>:323:18)
(Session info: chrome=114.0.5735.91)
Stacktrace:
Backtrace:
GetHandleVerifier [0x010CA813+48355]
(No symbol) [0x0105C4B1]
Any idea what is causing this exception pls ?
I tried microsoft edge, same issue.
</details>
# 答案1
**得分**: 1
由于您正在使用Selenium版本`v4.10.0`,设置`driver.exe`路径是可选的。您可以将下面的代码替换为:
```python
browser = webdriver.Chrome()
参考 - https://stackoverflow.com/a/76463081/7598774
英文:
Since you are using selenium version v4.10.0
, setting the driver.exe
path is optional. You can replace the below code:
DRIVER_PATH = 'I://Decoded//chromedriver.exe'
s=Service(DRIVER_PATH)
browser = webdriver.Chrome(service=s)
To simply:
browser = webdriver.Chrome()
Reference - https://stackoverflow.com/a/76463081/7598774
答案2
得分: 0
WebDriverException: Message: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function
这个错误消息是由于ChromeDriver二进制文件的最近更改引起的回归问题。
这个问题在org.openqa.selenium.WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: value.hasOwnProperty is not a function at Object.stringify线程中讨论,并且这个问题需要在ChromeDriver中修复。
英文:
This error message...
WebDriverException: Message: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function
...is a regression issue due to recent changes in the ChromeDriver binary.
This issue was discussed in the thread org.openqa.selenium.WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: value.hasOwnProperty is not a function at Object.stringify and this issue requires fix in ChromeDriver.
tl; dr
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论