Home > Web Front-end > JS Tutorial > How to Resolve \'AttributeError: \'module\' object has no attribute \'GetEval\'\' When Executing JavaScript in Selenium with Python?

How to Resolve \'AttributeError: \'module\' object has no attribute \'GetEval\'\' When Executing JavaScript in Selenium with Python?

Susan Sarandon
Release: 2024-10-29 07:51:30
Original
973 people have browsed it

How to Resolve

Running Javascript in Selenium Using Python

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>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template