Python Selenium Webdriver JSON.stringify is not a function

huangapple go评论60阅读模式
英文:

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__
&#39;4.10.0&#39;

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&#39;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 = &#39;I://Decoded//chromedriver.exe&#39;
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中修复

tl; dr
使用Selenium和ChromeDriver时,出现WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function

英文:

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

WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function using Selenium and ChromeDriver

huangapple
  • 本文由 发表于 2023年6月19日 22:32:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76507619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定