{"id":2993,"date":"2020-07-24T05:24:23","date_gmt":"2020-07-24T05:24:23","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=2993"},"modified":"2020-07-24T06:14:00","modified_gmt":"2020-07-24T06:14:00","slug":"the-same-value-of-all-the-locators-for-multiple-elements","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/","title":{"rendered":"The same value of all the locators for multiple elements"},"content":{"rendered":"<h2>Solution for the same value of all the locators for multiple elements:<\/h2>\n<p>Here we will handle the situation where all the locators of an element shared the same value with some other element or elements. By simple means, it is not possible. Here\u2019s the DOM snippet where the target element is:<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/07\/multiple-elements.png\" alt=\"multiple elements\"\/><\/p>\n<h3>Issue<\/h3>\n<p>As you can see, the locators such as ID, Class name, tag are the same for both \u201cAssign a different user\u201d and \u201cEdit user details\u201d links. Our main goal is to get the \u201cEdit user details\u201d link clicked via <a href=\"https:\/\/studysection.com\/blog\/common-exceptions-in-selenium\/\">Selenium<\/a>. For this, we need to facilitate locating the aforementioned element. The issue is that if we try to locate the element simply via ID etc, the action(click) will be performed on the \u201cAssign a different user\u201d link since it is placed above the target element in the DOM or it will throw an error such as \u201cElement not found\u201d. This thing is inconsistent but mostly the former behavior occurs. <\/p>\n<h3>Solution<\/h3>\n<p>You could use the link text, but using it alone could not solve this problem, since, for each user these links are present, hence it will be unstable including the transfer link. There are two ways you can find a particular element in this case:<\/p>\n<p>1. One option is to find the Xpath of the parent Div and append the target link location to the path which will always be unique. Hence, it was able to find that particular element. Here\u2019s the complete path that can be there &#8211;<br \/>\n\u201c\/\/*[@id=&#8221;fsExistingUserEnrollements&#8221;]\/div\/div[3]\/div[4]\/a[3]\u201d<\/p>\n<p>Till \u2018div[4] it is the XPath of the div and then tag name is written along with the list sub-scripting which is a[3].\u2019 You can see the Screenshot of the complete process below which is done inside the Chrome browser.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/07\/multiple-elements-1.png\" alt=\"\"\/><\/p>\n<p>2. The second option is to use XPath or CSS Selector in combination with the link text. This is how it can be done &#8211; \u201c\/\/*[@id=&#8221;fsExistingUserEnrollements&#8221;]\/\/div[4]\/\/a[text() = &#8216;Edit user details&#8217;]\u201d . Here text() function is being used to accept the link text. Note &#8211; Using \u2018\/\/\u2019 allows us to remove the parent divs to make it simpler and in case one of them is removed or their position changes, our XPath will still work.<br \/>\n<img decoding=\"async\" src=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/07\/multiple-elements-2.png\" alt=\"\"\/><\/p>\n<h3>Tip<\/h3>\n<p>Whenever you have to find an element, type it inside the inspect element search box using Ctrl + F. There should only be one matching result &#8211; i.e. 1 of 1 unless you are trying to find multiple elements. <\/p>\n<p><small>StudySection offers <a href=\"https:\/\/www.studysection.com\/financial-accounting-foundation\">Financial accounting certification<\/a> for individuals in the commerce field with basic or advanced level skills in accounting. If you need to prove your skills in Financial accounting, you can go through StudySection\u2019s accounting certification exam and get a certification that can add more value to your resume.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Solution for the same value of all the locators for multiple elements: Here we will handle the situation where all<\/p>\n","protected":false},"author":1,"featured_media":3003,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[494,501,124],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The same value of all the locators for multiple elements - SS Blog<\/title>\n<meta name=\"description\" content=\"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.\" \/>\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\/the-same-value-of-all-the-locators-for-multiple-elements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The same value of all the locators for multiple elements - SS Blog\" \/>\n<meta property=\"og:description\" content=\"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\" \/>\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=\"2020-07-24T05:24:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-07-24T06:14:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/07\/img.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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"The same value of all the locators for multiple elements\",\"datePublished\":\"2020-07-24T05:24:23+00:00\",\"dateModified\":\"2020-07-24T06:14:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\"},\"wordCount\":471,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"Elements\",\"multiple\",\"selenium\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\",\"url\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\",\"name\":\"The same value of all the locators for multiple elements - SS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2020-07-24T05:24:23+00:00\",\"dateModified\":\"2020-07-24T06:14:00+00:00\",\"description\":\"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The same value of all the locators for multiple elements\"}]},{\"@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":"The same value of all the locators for multiple elements - SS Blog","description":"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.","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\/the-same-value-of-all-the-locators-for-multiple-elements\/","og_locale":"en_US","og_type":"article","og_title":"The same value of all the locators for multiple elements - SS Blog","og_description":"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.","og_url":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2020-07-24T05:24:23+00:00","article_modified_time":"2020-07-24T06:14:00+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2020\/07\/img.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":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"The same value of all the locators for multiple elements","datePublished":"2020-07-24T05:24:23+00:00","dateModified":"2020-07-24T06:14:00+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/"},"wordCount":471,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["Elements","multiple","selenium"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/","url":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/","name":"The same value of all the locators for multiple elements - SS Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2020-07-24T05:24:23+00:00","dateModified":"2020-07-24T06:14:00+00:00","description":"Here we will handle the situation where all the locators of an element shared the same value with some other element or elements.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/the-same-value-of-all-the-locators-for-multiple-elements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"The same value of all the locators for multiple elements"}]},{"@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":1122,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/2993"}],"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=2993"}],"version-history":[{"count":5,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/2993\/revisions"}],"predecessor-version":[{"id":3001,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/2993\/revisions\/3001"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/3003"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=2993"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=2993"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=2993"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}