Question: I'm using Selenium with Python to generate inputs to credit card fields on a website. When you try send_keys to the field it always returns this error. I used different webdrivers (Chrome, Edge, Firefox) with the same effect. The error pops up before any input shows up in the field. from selenium import webdriver browser = webdriver.Chrome(r"C:\Users\m234234\Downloads\chromedriver_win32.exe") ... ... Element3 = browser.find_element(By.ID, 'scp_cardPage_csc_input') Element3.send_keys('231')  The element that is trying to access: <input autocomplete="off" maxlength="4" type="text" class="scp_text_input" name="csc" aria-required="true" aria-label="Security Code" aria-describedby="scp_cardPage_csc_error" id="scp_cardPage_csc_input" value="" size="5" onkeypress="return checkNum(event)">  Full error below WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: JSON.stringify is not a function at buildError (<anonymous>:323:18) (Session info: chrome=113.0.5672.126)   Update Once the script reaches this payment page (it's a third party payment page), it throws this same error when it tries to interact with the page in any way, even if I just try to retrieve current_url

Answer: json.stringify() The json.stringify() static method is a built-in function in JavaScript that converts a JavaScript value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified. The json.stringify() method takes one, two or three parameters, such as:  Value: The JavaScript object or value to be converted to a JSON string. Replacer (optional): It is a function that can be used to modify the values and properties of the object that is being converted. space (optional): A string or number that can be used to insert white space or line break characters into the output JSON string for readability purposes.   Root cause The error... TypeError: JSON.stringify is not a function  can occur if the program is trying to use the JSON.stringify() method on a non-object or when the method is not defined for a particular object. As an example: var person = "undetectedSelenium"; var jsonString = JSON.stringify(name); console.log(jsonString);  In the above code block we are trying to convert a string value to a JSON string using the JSON.stringify() method. JSON.stringify() method only works with JavaScript objects and arrays. Calling this method on a simple string value will result in this error. To fix this error, we can wrap the string value in an object or an array as follows: var person = "undetectedSelenium"; var jsonObject = { "name": person }; var jsonString = JSON.stringify(jsonObject); console.log(jsonString);   Some common causes Some of the most common causes of this error are:  Using an Older Version of JavaScript Incorrect Syntax Overwriting the JSON Object Incorrect Data Type   This usecase In this usecase it seems the script is unable to locate the element using the following line of code: Element3 = browser.find_element(By.ID, 'scp_cardPage_csc_input')  effectively Element3 remains a non-object. Hence the error is raised.  Possible fixes There are a couple of approaches to fix up this error as follows:  Verify if the json.stringify() method is defined and incase it isn't define a new function that converts an object to a JSON string. This solution is useful in older browsers that doesn't support the JSON object natively. if (typeof JSON.stringify !== 'function') { JSON.stringify = function(obj) { // code to convert obj to a JSON string }; }   Check if the obj variable is a valid JSON object before calling the json.stringify() method which can prevent the type error from being thrown when trying to call the method on a non-object. if (typeof obj === 'object' && obj !== null) { var jsonString = JSON.stringify(obj); }   Using a third-party JSON library, like MyJSON to convert the object to a JSON string. var jsonString = MyJSON.stringify(obj);   Using a try-catch block to prevent the program from crashing if the error occurs: try { var jsonString = JSON.stringify(obj); } catch (e) { console.error('Error: ' + e.message); }     Road ahead This issue isn't related to Selenium Python Client but an issue with the sourcecode of ChromeDriver and needs to be addressed by the ChromeDriver team.  tl; dr  [🐛 Bug]: org.openqa.selenium.WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: value.hasOwnProperty is not a function at Object.stringify Issue 4481: org.openqa.selenium.WebDriverException: unknown error: Runtime.callFunctionOn threw exception: TypeError: value.hasOwnProperty is not a function at Object.stringify