When attempting to execute a Javascript snippet in Selenium using Python, you might encounter an error like "AttributeError: 'module' object has no attribute 'GetEval'." Here's how to resolve this issue:
Problem:
As mentioned in the question, calling selenium.GetEval() to execute Javascript in Selenium using Python raises an AttributeError.
Solution:
The correct method for executing Javascript in Selenium using Python is browser.execute_script. Here's how you can modify the provided code:
<code class="python">from selenium import webdriver import selenium from selenium.common.exceptions import NoSuchElementException from selenium.webdriver.common.keys import Keys import time # ... (unchanged code) # Execute Javascript browser.execute_script("submitForm('patchCacheAdd',1,{'event':'ok'});return false") # ... (unchanged code)</code>
This code will now successfully execute the provided Javascript snippet.
Example Demonstration:
Refer to the answer provided in the original source for a detailed example of using browser.execute_script to execute Javascript in Selenium using Python.
The above is the detailed content of How to Resolve \'AttributeError: \'module\' object has no attribute \'GetEval\'\' When Executing JavaScript in Selenium with Python?. For more information, please follow other related articles on the PHP Chinese website!