{"id":5741,"date":"2022-03-25T04:32:30","date_gmt":"2022-03-25T04:32:30","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=5741"},"modified":"2022-03-25T06:28:15","modified_gmt":"2022-03-25T06:28:15","slug":"webdriver-and-webelements-in-selenium","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/","title":{"rendered":"WebDriver and WebElements in Selenium"},"content":{"rendered":"<p>WebDrvier is a collection of related methods. WebElements are buttons, text boxes, checkboxes, drop-down menus, hyperlinks, etc. on a web application. The Building Blocks for <a href=\"https:\/\/blog.webnersolutions.com\/introduction-to-selenium-grid\/\">Selenium <\/a> WebDriver is to first locate a WebElement then perform an action on the WebElement.<br \/>\nA configuration for WebDriver is required before importing its packages. The driver object and methods are put to use after importing a WebDrvier package.<\/p>\n<p><strong>WebDriver Packages and Classes:<\/strong> The WebDriver interface contains several classes. Each class is utilized through an imported package. In order to use WebDrvier, the appropriate package must be imported to execute specific commands. As an example, the package \u201corg.openqa.selenium.chrome\u201d must be imported to use class \u201cChrome Driver\u201d to execute a command that loads Google Chrome browser. The following is an example of importing a package for Firefox driver:<\/p>\n<p><code>import org.openqa.selenium.WebDriver;<br \/>\nimport org.openqa.selenium.firefox.FirefoxDriver;<\/code><\/p>\n<p><strong>WebDriver Object and Methods:<\/strong> Executions of the WebDriver commands are carried out through the driver object. The driver object is the main WebDriver component, which assists with locating and performing actions on WebElements. Like objects in Java programming, the driver object must be instantiated \u201ccreated\u201d before it is used. The following is an example of instantiating a Firefox driver object:<\/p>\n<p><code>WebDriver driver = newFirefoxDriver();<\/code><\/p>\n<p>After creating a driver object, the WebDriver methods are available to perform actions on a browser. An automation engineer can type the word \u201cdriver\u201d followed by the dot operator (.) to view the methods. <\/p>\n<p>The following is a screenshot of the WebDriver methods<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/03\/Selenium-code.png\" alt=\"Selenium-code\"\/><\/p>\n<p>The WebDriver methods either return a value or return no value. For example, the findElement() method <strong>\u201cfindElement(By argO) : WebElement\u201d<\/strong> has a return value of \u201cWebElement\u201d which indicates a WebElement will be returned to the method. On the other hand, the close() method <strong>\u201cclose(): void\u201d<\/strong>  has a return value of \u201cvoid\u201d which indicates a value will not be returned. The same with get() method <strong>\u201cget(String argO) : void\u201d<\/strong> which returns a value of void. However, the get() method receives a String parameter <strong>\u201cString argO\u201d<\/strong>. All strings have double quotes surrounding it\u2019s value.<\/p>\n<p><em>The following is a complete syntax utilizing get() method for loading a new web page.<\/em><\/p>\n<p><strong><em>Note:<\/em><\/strong>  <strong>driver.manage().window().maximize()<\/strong> is a statement of maximizing\/enlarging the window.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/03\/Selenium-code1.png\" alt=\"Selenium-code1\" \/><\/p>\n<h2>The following describes each WebDriver Method:<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/03\/Selenium-code2.png\" alt=\"Selenium-code2\" \/><\/p>\n<p><strong>Locate WebElements via HTML:<\/strong> All web applications and browsers contain WebElements <strong>\u201ci.e, buttons, links, etc.\u201d<\/strong><br \/>\nThe WebElements are derived from HyperText Markup Language (HTML). HTML is the standard markup language for creating web applications. Furthermore, each browser reads an HTML document to display the browser pages.<\/p>\n<p>A great deal of HTML markup tags includes an opening (also known as starting) tag, a closing (also known as ending) tag, and at least one attribute. In regards to web applications and browsers, the markup tags determine the characteristics of a WebElement. Attributes provide additional information about the WebElement. It is important to know that attributes are defined in the opening tag.<\/p>\n<p>Both tags have the same name surrounded by angle brackets ( &lt; > ). However, the difference between an opening tag and a closing tag is the forward-slash ( \/ ). Closing tags must include a forward slash before the tag name. Unlike the tags, an attribute contains a name\/value pair. The following is the syntax for an opening tag, closing tag, and attribute name\/value pair.<\/p>\n<p><strong>Syntax<\/strong><br \/>\n<code>&lt;Opening AttributeName=\u201dAttribute value\u201d><\/code><\/p>\n<p><strong>Content placed in between the tags<\/strong><br \/>\n<code>&lt;\/Closing><\/code><\/p>\n<p><em><strong>Note:<\/strong><\/em> Some elements do not contain a closing tag<\/p>\n<p><small><em>Get certification for your knowledge in the fundamentals of Computer functioning by clearing the <a href=\"https:\/\/studysection.com\/computer-networks-advanced\">Computer Certification<\/a> exam conducted by StudySection. After going through this Computer Certification exam, you will be able to evaluate your basic knowledge of computers<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>WebDrvier is a collection of related methods. WebElements are buttons, text boxes, checkboxes, drop-down menus, hyperlinks, etc. on a web<\/p>\n","protected":false},"author":1,"featured_media":5745,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[124,681],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WebDriver and WebElements in Selenium - SS Blog<\/title>\n<meta name=\"description\" content=\"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.\" \/>\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\/webdriver-and-webelements-in-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WebDriver and WebElements in Selenium - SS Blog\" \/>\n<meta property=\"og:description\" content=\"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\" \/>\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=\"2022-03-25T04:32:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-03-25T06:28:15+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/03\/Selenium.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=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"WebDriver and WebElements in Selenium\",\"datePublished\":\"2022-03-25T04:32:30+00:00\",\"dateModified\":\"2022-03-25T06:28:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\"},\"wordCount\":595,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"selenium\",\"WebDriver\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\",\"url\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\",\"name\":\"WebDriver and WebElements in Selenium - SS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2022-03-25T04:32:30+00:00\",\"dateModified\":\"2022-03-25T06:28:15+00:00\",\"description\":\"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WebDriver and WebElements in Selenium\"}]},{\"@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":"WebDriver and WebElements in Selenium - SS Blog","description":"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.","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\/webdriver-and-webelements-in-selenium\/","og_locale":"en_US","og_type":"article","og_title":"WebDriver and WebElements in Selenium - SS Blog","og_description":"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.","og_url":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2022-03-25T04:32:30+00:00","article_modified_time":"2022-03-25T06:28:15+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/03\/Selenium.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":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"WebDriver and WebElements in Selenium","datePublished":"2022-03-25T04:32:30+00:00","dateModified":"2022-03-25T06:28:15+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/"},"wordCount":595,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["selenium","WebDriver"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/","url":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/","name":"WebDriver and WebElements in Selenium - SS Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2022-03-25T04:32:30+00:00","dateModified":"2022-03-25T06:28:15+00:00","description":"WebDrvier is a collection of related methods. A configuration for WebDriver is required before importing its packages.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/webdriver-and-webelements-in-selenium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"WebDriver and WebElements in Selenium"}]},{"@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":2029,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5741"}],"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=5741"}],"version-history":[{"count":3,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5741\/revisions"}],"predecessor-version":[{"id":5750,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5741\/revisions\/5750"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/5745"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=5741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=5741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=5741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}