Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (29.3k points)

I am totally new to Selenium. I want to execute a javascript snippet in the following code(as commented in the code) but can't do so. Please help.

from selenium import webdriver

import selenium

from selenium.common.exceptions import NoSuchElementException

from selenium.webdriver.common.keys import Keys

import time

patch = raw_input("Enter patch number\n")

rel = raw_input("Enter release\n")

plat = raw_input("Enter port\n")

browser = webdriver.Firefox()

browser.get("xxxxxxxxxxxxxxxxx")

pdtfamily = browser.find_element_by_id("prodFamilyID")

pdtfamily.send_keys("Database & Tools" + Keys.TAB)

time.sleep(5)

pdt = browser.find_element_by_id("productID")

pdt.send_keys("Intelligent Agent" + Keys.TAB)

time.sleep(5)

pdt1 = browser.find_element_by_id("patchCacheChkBxID")

pdt1.send_keys(Keys.SPACE)

time.sleep(5)

pdt7 =  browser.find_element_by_id("M__Idf")

pdt7.send_keys(plat)

pdt8 =  browser.find_element_by_id("M__Idg")

pdt8.send_keys("American English")

# Here I want to execute this javascript - "submitForm('patchCacheAdd',1,{'event':'ok'});return false"

browser.close()

If I use -
selenium.GetEval("submitForm('patchCacheAdd',1,{'event':'ok'});return false")
it errors out as -
AttributeError: 'module' object has no attribute 'GetEval'I

1 Answer

0 votes
by (50.2k points)

For this problem use

Browser.execute_script instead of using selenium.GetEval

Let’s see an example of implementing Browser.execute_script

execute_script() will help you to run the script 

>>wd.execute_script("return 5")

5

>>wd.execute_script("return true")

True

This helps you to run your script instead of selenium.GetEval

For more details: https://selenium-python.readthedocs.io/api.html#selenium.webdriver.remote.webdriver.WebDriver.execute_script

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...