{"id":5923,"date":"2022-07-18T05:04:00","date_gmt":"2022-07-18T05:04:00","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=5923"},"modified":"2022-07-18T05:04:00","modified_gmt":"2022-07-18T05:04:00","slug":"find-webelement-by-name","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/","title":{"rendered":"Find WebElement By Name"},"content":{"rendered":"<p>There are times when an id attribute may or may not be present on a web page. If that&#8217;s the case, an automation engineer had to search for a name attribute&#8217;s value. The process of locating an element by name is similar to that of locating an element by ID locator type. The name attribute is usually located in WebElements like text fields and buttons. However, unlike the id attribute, which contains a unique value, the name attribute can contain the same value within HTML\u2019s source code. The following is a screenshot of Linkedin and its HTML markup tags for a colleague\u2019s First and Last Name:<\/p>\n<h2>LinkedIn\u2019s Home Screen (Colleague\u2019s First and Last Name)<\/h2>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements1.png\" alt=\"WebElements1\"\/><\/p>\n<h3>HTML for LinkedIn&#8217;s Colleague\u2019s First and Last Name<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements2.png\" alt=\"WebElements2\"\/><\/p>\n<p><strong>Note:<\/strong> The HTML markup tags do not contain an id attribute for Colleague\u2019s First Name and Last Name:<br \/>\nEnter some Text for Colleague&#8217;s First and Last Names in the Text fields.<\/p>\n<p><strong><em>The following is code for entering text in LinkedIn\u2019s Colleague First and Last Name text fields via name attribute:<\/em><\/strong><br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements3.png\" alt=\"WebElements3\"\/><\/p>\n<h3>Perform actions on the Colleague\u2019s First Name Text field<\/h3>\n<ul>\n<li><strong>Line 8<\/strong> \u201cWebDriver driver\u201d is the interface for driving the browser. Currently, the object reference variable \u201cdriver\u201d points to nothing but will point to a Chrome Driver object in a subsequent line \u201cdriver = new ChromeDriver()\u201d.<\/li>\n<li><strong>Line 13<\/strong> tells Selenium where the executable file for the Chrome driver is located via System.setProperty. The executable file operates like a bridge between Selenium and the browser. All browsers except Firefox require an executable file. The following are parameters for System.setProperty:\n<ul>\n<li>key = webdriver.chrome.driver<\/li>\n<li>Note: Value is the path location of the executable file.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Line 14<\/strong> \u201cdriver = new ChromeDriver()\u201d is an implementation of the WebDriver interface. The object reference variable \u201cdriver\u201d is pointing to the new ChromeDriver() which means testing is controlled on the Chrome browser.<\/li>\n<li><strong>Line 16<\/strong>  \u201cdriver.get(\u201c<a href=\"http:\/\/www.linkedin.com\/\">https\u201d\/\/www.linkedin.com\/<\/a>\u201d)  loads a new LinkedIn Home page in the current browser window<\/li>\n<li><strong>Line 22<\/strong> \u201cdriver.quit()\u201d quits the driver instance and closes the open browser window.<\/li>\n<li><strong>Line 28<\/strong> \u201cdriver.findElement(By.name(\u201cfirst\u201d)).sendKeys(\u201cRex\u201d)\u201d:\n<ul>\n<li>driver-WebDriver object reference variable that assists with finding a WebElement<\/li>\n<li>findElement &#8211; a WebDriver method that finds the text field WebElement \u201cFirst Name\u201d on LinkedIn\u2019s Home page<\/li>\n<li>(By.name(\u201cfirst\u201d)) &#8211; By and name are parameters of the findElement WebDriver method. By is an object which locates elements and the name is the locate type. The name locator type accepts a string parameter \u201cfirst\u201d which is the value of the HTML name attribute<\/li>\n<li>sendKeys(\u201cRex\u201d) &#8211; types the text \u201cRex\u201d in the Colleague\u2019s First Name text field<\/li>\n<\/ul>\n<\/li>\n<li><strong>Line 29<\/strong>  \u201cdriver.findElement(By.name(\u201clast\u201d)).sendKeys(\u201cJones\u201d)\u201d:\n<ul>\n<li>driver-WebDriver object reference variable that assists with finding a WebElement<\/li>\n<li>findElement-a WebDriver method that finds the text field WebElement  \u201cFirstname\u201d on LinkedIn\u2019s Home page<\/li>\n<li>(By.name(\u201clast\u201d)) &#8211; By.name are parameters of the findElement WebDriver method. By is an object which locates elements and the name is the locator type. The name locator type accepts a string parameter \u201clast\u201d which is the value of the HTML name attribute.<\/li>\n<li>sendKeys(\u201cJones\u201d) &#8211; types the text  \u201cJones\u201d in the Colleague\u2019s Last Name text field<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>The following is a screenshot of Linkedin\u2019s Home page after entering text in the Colleague&#8217;s First and Last Name field:<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements4.png\" alt=\"WebElements4\"\/><br \/>\nEnter Text in the Colleague\u2019s First and Last Name Text field<\/p>\n<p><small><em>If you have skills in PHP programming and you want to enhance your career in this field, a PHP certification from StudySection can help you reach your desired goals. Both beginner level and expert level <a href=\"https:\/\/www.studysection.com\/php-web-developer-foundation-diploma\">PHP Certification Exams<\/a> are offered by StudySection along with other programming certification exams. <\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are times when an id attribute may or may not be present on a web page. If that&#8217;s the<\/p>\n","protected":false},"author":1,"featured_media":5924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[124,796],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selenium-Find WebElement By Name - StudySection Blog<\/title>\n<meta name=\"description\" content=\"There are times when an id attribute not be present on a web. If that&#039;s the case, an automation engineer had to search for a name value.\" \/>\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\/find-webelement-by-name\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selenium-Find WebElement By Name - StudySection Blog\" \/>\n<meta property=\"og:description\" content=\"There are times when an id attribute not be present on a web. If that&#039;s the case, an automation engineer had to search for a name value.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\" \/>\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-07-18T05:04:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements.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<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Find WebElement By Name\",\"datePublished\":\"2022-07-18T05:04:00+00:00\",\"dateModified\":\"2022-07-18T05:04:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\"},\"wordCount\":617,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"selenium\",\"WebElement\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\",\"url\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\",\"name\":\"Selenium-Find WebElement By Name - StudySection Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2022-07-18T05:04:00+00:00\",\"dateModified\":\"2022-07-18T05:04:00+00:00\",\"description\":\"There are times when an id attribute not be present on a web. If that's the case, an automation engineer had to search for a name value.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Find WebElement By Name\"}]},{\"@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":"Selenium-Find WebElement By Name - StudySection Blog","description":"There are times when an id attribute not be present on a web. If that's the case, an automation engineer had to search for a name value.","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\/find-webelement-by-name\/","og_locale":"en_US","og_type":"article","og_title":"Selenium-Find WebElement By Name - StudySection Blog","og_description":"There are times when an id attribute not be present on a web. If that's the case, an automation engineer had to search for a name value.","og_url":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2022-07-18T05:04:00+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2022\/07\/WebElements.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"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Find WebElement By Name","datePublished":"2022-07-18T05:04:00+00:00","dateModified":"2022-07-18T05:04:00+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/"},"wordCount":617,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["selenium","WebElement"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/find-webelement-by-name\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/","url":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/","name":"Selenium-Find WebElement By Name - StudySection Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2022-07-18T05:04:00+00:00","dateModified":"2022-07-18T05:04:00+00:00","description":"There are times when an id attribute not be present on a web. If that's the case, an automation engineer had to search for a name value.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/find-webelement-by-name\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/find-webelement-by-name\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Find WebElement By Name"}]},{"@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":183,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5923"}],"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=5923"}],"version-history":[{"count":1,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5923\/revisions"}],"predecessor-version":[{"id":5929,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5923\/revisions\/5929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/5924"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=5923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=5923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=5923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}