{"id":1228,"date":"2019-10-09T04:51:48","date_gmt":"2019-10-09T04:51:48","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=1228"},"modified":"2021-01-20T04:54:38","modified_gmt":"2021-01-20T04:54:38","slug":"selenium-webdriver-using-python-tutorial","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/","title":{"rendered":"Selenium Webdriver Using python tutorial"},"content":{"rendered":"<p>Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser &#038; cross-OS testing. Python is an easy to use language that allows the fast development of our script. It provides a large set of libraries to help us.<br \/>\n<br \/>We are going to use \u2018Chrome driver\u2019 for this. You can just change the name of the web driver to interact with the browser of your choice. You can find out how to set up selenium with chrome using this article. <a href=\"http:\/\/jonathansoma.com\/lede\/foundations-2018\/classes\/selenium\/selenium-windows-install\/\" style=\"color:blue;\">Setup selenium with chrome<\/a><br \/>\n<br \/>\nSuppose we want to login to Gmail. Here\u2019s how you would do it:<br \/>\n<\/p>\n<ol>\n<li>First import the <a href=\"https:\/\/studysection.com\/selenium-webdriver-feature-advanced\" style=\"color:blue;\">selenium <\/a>and time libraries:\n<ul>\n<li>In first library, we are importing webdriver module which will allow us to conduct different operations.<\/li>\n<li>From time library, we can use time.sleep(s) to stop execution for \u2018s\u2019 seconds. It helps in avoiding errors that arise when the page is not loaded properly.<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/selenium.png\" alt=\"\"\/>\n<\/li>\n<li>Type these lines:<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/webdriver.png\" alt=\"\" \/><\/p>\n<ul>\n<li>First-line tells which browser is used to execute the script. You could have used Firefox as well. The variable name could have been anything else. The most common are driver and browser.<\/li>\n<li>Next,  we give the URL of the site that we want to reach.<\/li>\n<li>In the next line, we are maximizing the browser window. You may skip it if it is comfortable using the full window.<\/li>\n<li>Using implicit wait, we are waiting for the page to load properly before we do any of the operations<\/li>\n<\/ul>\n<\/li>\n<p><\/br><\/p>\n<li>Next, we\u2019ll find some locators to identify elements on the web page and do operations on them.<\/li>\n<\/ol>\n<p><strong>Locators<\/strong><br \/>\nLocators are a way of finding one or more elements on a web page.<br \/>\n<\/br><\/p>\n<ol>\n<li>Go to the URL on the browser, right-click on the element you want to pick and click on inspect element(DOM: Document Object Model).<\/li>\n<li>Check for attributes such as ID, Name, Xpath, etc.<\/li>\n<li>Copy it and use it as follows.<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/edit.png\" alt=\"\"\/><\/p>\n<ul>\n<li><strong>find_element_by_id<\/strong> &#8211;  Try to use the Id wherever it is available as it is always unique. However, if the ID and name are the same, you can use whatever you want.<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/find-element.png\" alt=\"\"\/><\/p>\n<li><strong>find_element_by_name<\/strong> &#8211; Syntax of name is similar to Id.<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/find-element-by-name.png\" alt=\"\"\/><br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/email.png\" alt=\"\" \/><\/p>\n<li><strong>find_element_by_xpath<\/strong> &#8211; Where No Id or name is given, xpath can be used. Right click on the element, hover over copy and click on copy Xpath.<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/xpath.png\" alt=\"\"\/><\/p>\n<li><strong>Find_element_by_link_text<\/strong> &#8211; You can directly use these lines without using a variable. <\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/link.png\" alt=\"\"\/><\/p>\n<li><strong>Find_element_by_partial_link_text<\/strong> &#8211; You can just use some part of the text to identify the element. If there are multiple elements with text \u2018Learn\u2019, it will pick the first element that has \u201cLearn\u201d in it. This is true for all the locators.You will have to use some other locator such as xpath or link_text etc or whatever is available.<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/partial-link.png\" alt=\"\" \/><\/p>\n<li><strong>Find_element_by_tag_name<\/strong> &#8211; sometimes there is no attribute that can be useful in identifying the element. In that case you can use tag name. Generally it is used when you want to find multiple elements having that tag. Eg &#8211; use anchor tag<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/tagname.png\" alt=\"\"\/><\/p>\n<li><strong>Find_element_by_class_name<\/strong> &#8211; class is very useful when you want to find multiple elements of a particular class, however, it is useful for finding single element as well. <\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/class-name.png\" alt=\"\" \/><\/p>\n<li><strong>Find_element_by_css_selector<\/strong> &#8211;  Like Xpath, it is useful when trying to identify a button, input etc. Right click on the element, hover over the \u2018copy\u2019 and click on \u2018Copy Selector\u2019. This might seem complicated but you just have to copy it. I could have taken a simpler example but I wanted to show you the full picture.<\/li>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/css-selector.png\" alt=\"\"\/>\n<\/ul>\n<p>Apart from the above methods, there\u2019s another way to find an element:<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/send-key.png\" alt=\"\"\/><br \/>\nNote &#8211; It is required to import <strong>\u201cfrom selenium.webdriver.common.by import By\u201d<\/strong>. This method is useful when you need to use an explicit wait. I\u2019ll explain this in the next Post.<br \/>\n<\/br><br \/>\nHere\u2019s the complete Code for logging into your Gmail account.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/import.png\" alt=\"\" \/><br \/>\n<small><strong>Note &#8211; This is a working example, you can run it as it is. You can do this without defining it inside a function but I suggest using a function So that you can call it anywhere anytime.<\/strong><\/small><\/p>\n<p><small><em>StudySection gives an opportunity to beginners and experts in .NET framework to go through StudySection\u2019s .NET certification exam and get a <a href=\"https:\/\/studysection.com\/asp-.net-4.5-foundation\" style=\"color:blue;\">.NET certification<\/a> for enhancement of career in programming. If you have knowledge of the .NET framework then you can get a certificate through an online exam at StudySection<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser &#038; cross-OS testing.<\/p>\n","protected":false},"author":1,"featured_media":1229,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[189,33,124,22,83],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>StudySection Blog for Selenium Webdriver Using python tutorial<\/title>\n<meta name=\"description\" content=\"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser &amp; cross-OS testing.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"StudySection Blog for Selenium Webdriver Using python tutorial\" \/>\n<meta property=\"og:description\" content=\"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser &amp; cross-OS testing.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-09T04:51:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-01-20T04:54:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/python.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Selenium Webdriver Using python tutorial\",\"datePublished\":\"2019-10-09T04:51:48+00:00\",\"dateModified\":\"2021-01-20T04:54:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\"},\"wordCount\":761,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Framework\",\"Python\",\"selenium\",\"testing\",\"web\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\",\"url\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\",\"name\":\"StudySection Blog for Selenium Webdriver Using python tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2019-10-09T04:51:48+00:00\",\"dateModified\":\"2021-01-20T04:54:38+00:00\",\"description\":\"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser & cross-OS testing.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Selenium Webdriver Using python tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"StudySection Blog for Selenium Webdriver Using python tutorial","description":"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser & cross-OS testing.","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:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"StudySection Blog for Selenium Webdriver Using python tutorial","og_description":"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser & cross-OS testing.","og_url":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2019-10-09T04:51:48+00:00","article_modified_time":"2021-01-20T04:54:38+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2019\/10\/python.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Selenium Webdriver Using python tutorial","datePublished":"2019-10-09T04:51:48+00:00","dateModified":"2021-01-20T04:54:38+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/"},"wordCount":761,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Framework","Python","selenium","testing","web"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/","url":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/","name":"StudySection Blog for Selenium Webdriver Using python tutorial","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2019-10-09T04:51:48+00:00","dateModified":"2021-01-20T04:54:38+00:00","description":"Selenium Webdriver is an automation framework that allows us to interact with a browser. It supports cross-browser & cross-OS testing.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/selenium-webdriver-using-python-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Selenium Webdriver Using python tutorial"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":466,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/1228"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=1228"}],"version-history":[{"count":15,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/1228\/revisions"}],"predecessor-version":[{"id":3841,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/1228\/revisions\/3841"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/1229"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=1228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=1228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=1228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}