{"id":372488,"date":"2023-03-23T13:27:20","date_gmt":"2023-03-23T13:27:20","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=372488"},"modified":"2023-04-14T06:42:53","modified_gmt":"2023-04-14T06:42:53","slug":"how-to-run-first-script-in-selenium-with-python","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/","title":{"rendered":"How to run First Script in Selenium with Python"},"content":{"rendered":"\n<p>Selenium is a popular open-source automation testing tool used to automate web browsers. It allows we  to simulate user interaction with a website, automate repetitive tasks, and test web applications. Python is one of the most popular programming languages used for Selenium automation testing.<\/p>\n\n\n\n<p>To configure the Selenium with python <a href=\"https:\/\/webkul.com\/blog\/implementation-of-selenium-with-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Click Here<\/a><\/p>\n\n\n\n<p>In this blog, we will guide we through the steps to run our first Selenium script using Python. We assume that we have already installed Python and Selenium on our system.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Launch the browser<\/h3>\n\n\n\n<p>The first step is to launch the browser. For this example, we will use Google Chrome. We can download the latest version of Chrome from the official website. Once we have installed Chrome, we also need to download the appropriate driver for Our operating system. We can download the Chrome driver from the following link:  <a href=\"https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/downloads.\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/sites.google.com\/a\/chromium.org\/chromedriver\/downloads.<\/a><\/p>\n\n\n\n<p>After downloading the Chrome driver, we need to specify the path to the driver in our Selenium script.<\/p>\n\n\n\n<p>Here is the code to launch the Chrome browser:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">from selenium import webdriver\ndriver_path = &quot;path\/to\/chromedriver.exe&quot;\ndriver = webdriver.Chrome(executable_path=driver_path)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Navigate to a website<\/h3>\n\n\n\n<p>The next step is to navigate to a website. For this example, we will navigate to the Google homepage.<\/p>\n\n\n\n<p>Here is the code to navigate to the Google homepage:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">driver.get(&quot;https:\/\/www.google.com\/&quot;)<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Interact with the webpage<\/h3>\n\n\n\n<p>The final step is to interact with the webpage. For this example, we will search for the keyword &#8220;Python&#8221; on Google.<\/p>\n\n\n\n<p>Here is the code to interact with the webpage:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">search_box = driver.find_element_by_name(&quot;q&quot;)\nsearch_box.send_keys(&quot;Python&quot;)\nsearch_box.submit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Close the browser<\/h3>\n\n\n\n<p>After we have finished interacting with the webpage, we need to close the browser.<\/p>\n\n\n\n<p>Here is the code to close the browser:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">driver.quit()<\/pre>\n\n\n\n<p>The final script should look something like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">from selenium import webdriver\n\ndriver_path = &quot;path\/to\/chromedriver.exe&quot;\ndriver = webdriver.Chrome(executable_path=driver_path)\ndriver.get(&quot;https:\/\/www.google.com\/&quot;)\nsearch_box = driver.find_element_by_name(&quot;q&quot;)\nsearch_box.send_keys(&quot;Python&quot;)\nsearch_box.submit()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Run the script<\/h3>\n\n\n\n<p>Save the above code in a file named &#8220;selenium_example.py&#8221; and run it using the following command:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">python selenium_example.py<\/pre>\n\n\n\n<p>We should see the web browser launch and navigate to Google, enter a search query and display the search results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium is a popular open-source automation testing tool used to automate web browsers. It allows we to simulate user interaction with a website, automate repetitive tasks, and test web applications. Python is one of the most popular programming languages used for Selenium automation testing. To configure the Selenium with python Click Here In this blog, <a href=\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":507,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-372488","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to run First Script in Selenium with Python - Webkul Blog<\/title>\n<meta name=\"description\" content=\"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to run First Script in Selenium with Python - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-03-23T13:27:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-14T06:42:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jitendra Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jitendra Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\"},\"author\":{\"name\":\"Jitendra Kumar\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/99dc56ae952ad7fe9d2c53c9b7073da0\"},\"headline\":\"How to run First Script in Selenium with Python\",\"datePublished\":\"2023-03-23T13:27:20+00:00\",\"dateModified\":\"2023-04-14T06:42:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\"},\"wordCount\":332,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\",\"name\":\"How to run First Script in Selenium with Python - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2023-03-23T13:27:20+00:00\",\"dateModified\":\"2023-04-14T06:42:53+00:00\",\"description\":\"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to run First Script in Selenium with Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/99dc56ae952ad7fe9d2c53c9b7073da0\",\"name\":\"Jitendra Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1c8d4de619d7c3b4a35dde558fa19cedea3490169ff972780a7f0ecc335024a9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1c8d4de619d7c3b4a35dde558fa19cedea3490169ff972780a7f0ecc335024a9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Jitendra Kumar\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/jitendrakr-qa904\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to run First Script in Selenium with Python - Webkul Blog","description":"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/","og_locale":"en_US","og_type":"article","og_title":"How to run First Script in Selenium with Python - Webkul Blog","og_description":"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.","og_url":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2023-03-23T13:27:20+00:00","article_modified_time":"2023-04-14T06:42:53+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Jitendra Kumar","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Jitendra Kumar","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/"},"author":{"name":"Jitendra Kumar","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/99dc56ae952ad7fe9d2c53c9b7073da0"},"headline":"How to run First Script in Selenium with Python","datePublished":"2023-03-23T13:27:20+00:00","dateModified":"2023-04-14T06:42:53+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/"},"wordCount":332,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/","url":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/","name":"How to run First Script in Selenium with Python - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2023-03-23T13:27:20+00:00","dateModified":"2023-04-14T06:42:53+00:00","description":"This post will help you in getting started and running your Python-based automation test scripts. You can run Selenium with Python.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-run-first-script-in-selenium-with-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to run First Script in Selenium with Python"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/99dc56ae952ad7fe9d2c53c9b7073da0","name":"Jitendra Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1c8d4de619d7c3b4a35dde558fa19cedea3490169ff972780a7f0ecc335024a9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1c8d4de619d7c3b4a35dde558fa19cedea3490169ff972780a7f0ecc335024a9?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Jitendra Kumar"},"url":"https:\/\/webkul.com\/blog\/author\/jitendrakr-qa904\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/372488","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/507"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=372488"}],"version-history":[{"count":11,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/372488\/revisions"}],"predecessor-version":[{"id":376879,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/372488\/revisions\/376879"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=372488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=372488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=372488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}