execute_script driver method – Selenium Python Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout – Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more specifically, the HTML elements within a page. There are multiple strategies to find an element using Selenium, checkout – Locating Strategies. Selenium WebDriver offers various useful methods to control the session, or in other words, browser. For example, adding a cookie, pressing back button, navigating among tabs, etc. This article revolves around execute_script driver method in Selenium. execute_script method synchronously Executes JavaScript in the current window/frame. This is a big feature of selenium, because javascript can do everything with a website from hitting APIs to playing with live code. Syntax – execute_script(script, *args) Args – script: The JavaScript to execute. *args: Any applicable arguments for your JavaScript. Example – Now one can use execute_script method as a driver method as below – diver.get("https://www.geeksforgeeks.org/") driver.execute_script("alert("alert via selenium")") How to use execute_script driver method in Selenium Python ? To demonstrate, execute_script method of WebDriver in Selenium Python. Let’ s visit https://www.geeksforgeeks.org/ and operate on driver object. Program – # import webdriver from selenium import webdriver # create webdriver object driver = webdriver.Firefox() # get geeksforgeeks.org driver.get("https://www.geeksforgeeks.org/") # write script script = "alert('Alert via selenium')" # generate a alert via javascript driver.execute_script(script) Output – Browser generates alert as verified below – Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Last Updated : 15 May, 2020 Like Article Save Article Previous execute_async_script driver method - Selenium Python Next forward driver method - Selenium Python Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads find_element(By.Name) driver method - Selenium Python find_element(By.XPATH) driver method - Selenium Python find_element_by_class_name() driver method - Selenium Python find_element() driver method - Selenium Python find_element_by_css_selector() driver method - Selenium Python find_elements_by_name() driver method - Selenium Python find_elements_by_xpath() driver method - Selenium Python find_elements_by_link_text() driver method - Selenium Python find_elements_by_partial_link_text() driver method - Selenium Python find_elements_by_tag_name() driver method - Selenium Python Complete Tutorials Python Crash Course Python API Tutorial: Getting Started with APIs Advanced Python Tutorials Python Automation Tutorial OpenAI Python API - Complete Guide Like N NaveenArora Follow Article Tags : Python-selenium selenium Python Practice Tags : python Additional Information Current difficulty : Basic Vote for difficulty : Easy Normal Medium Hard Expert