Selenium webdriver can execute Javascript. After loading a page, you can execute any javascript you want. A webdriver must be installed for selenium to work.

All it takes is calling the method execute_script(js) where js is your javascript code.

Related course:

javascript

selenium execute javascript

The program below runs a one line javascript command after loading the page. This will show the alert box in the webpage.

1
2
3
4
5
6
7
8
from selenium import webdriver

driver=webdriver.Firefox()
driver.implicitly_wait(3)
driver.get("https://pythonbasics.org")
js = 'alert("Hello World")'
driver.execute_script(js)

selenium execute javascript

Download examples