{"id":800,"date":"2013-01-02T07:50:49","date_gmt":"2013-01-02T07:50:49","guid":{"rendered":"http:\/\/vskills.in\/certification\/tutorial\/?p=800"},"modified":"2024-04-12T14:13:13","modified_gmt":"2024-04-12T08:43:13","slug":"locating-by-xpath","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/","title":{"rendered":"Selenium Tutorials Selenium IDE | Locating by XPath"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a ref=\"magnificPopup\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\"><img loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"400\" src=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\" alt=\"Locating by XPath\" class=\"wp-image-93470\" srcset=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png 750w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16-300x160.png 300w\" sizes=\"auto, (max-width: 750px) 100vw, 750px\" \/><\/a><\/figure><\/div>\n\n\n<h3><strong>Selenium IDE | Locating by XPath<\/strong><\/h3>\n<p><strong>XPath<\/strong> is the language used for locating nodes in an XML document. As HTML can be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target elements in their web applications.<strong> XPath<\/strong> extends beyond (as well as supporting) the simple methods of locating by id or name attributes, and opens up all sorts of new possibilities such as locating the third checkbox on the page.<\/p>\n<p>One of the main reasons for using <strong>XPath<\/strong> is when you don\u2019t have a suitable id or name attribute for the element you wish to locate. You can use <strong>XPath<\/strong> to either locate the element in absolute terms (not advised), or relative to an element that does have an id or name attribute. <strong>XPath<\/strong> locators can also be used to specify elements via attributes other than id and name.<\/p>\n<p>Absolute <strong>XPaths<\/strong> contain the location of all elements from the root (html) and as a result are likely to fail with only the slightest adjustment to the application. By finding a nearby element with an id or name attribute (ideally a parent element) you can locate your target element based on the relationship. This is much less likely to change and can make your tests more robust.<\/p>\n<p>Since only <strong><tt>xpath<\/tt><\/strong> locators start with \u201c\/\/\u201d, it is not necessary to include the <strong><tt>xpath=<\/tt><\/strong> label when specifying an <strong>XPath<\/strong> locator.<\/p>\n<div>\n<table>\n<tbody>\n<tr>\n<td>\n<pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10<\/pre>\n<\/td>\n<td>\n<div>\n<pre> &lt;html&gt;\n  &lt;body&gt;\n   &lt;form id=\"loginForm\"&gt;\n    &lt;input name=\"username\" type=\"text\" \/&gt;\n    &lt;input name=\"password\" type=\"password\" \/&gt;\n    &lt;input name=\"continue\" type=\"submit\" value=\"Login\" \/&gt;\n    &lt;input name=\"continue\" type=\"button\" value=\"Clear\" \/&gt;\n   &lt;\/form&gt;\n &lt;\/body&gt;\n &lt;html&gt;<\/pre>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<ul>\n<li><tt>xpath=\/html\/body\/form[1]<\/tt> (3) &#8211; <em>Absolute path (would break if the HTML was changed only slightly)<\/em><\/li>\n<li><tt>\/\/form[1]<\/tt> (3) &#8211; <em>First form element in the HTML<\/em><\/li>\n<li><tt>xpath=\/\/form[@id='loginForm']<\/tt> (3) &#8211; <em>The form element with attribute named \u2018id\u2019 and the value \u2018loginForm\u2019<\/em><\/li>\n<li><tt>xpath=\/\/form[input\/@name='username']<\/tt> (3) &#8211; <em>First form element with an input child element with attribute named \u2018name\u2019 and the value \u2018username\u2019<\/em><\/li>\n<li><tt>\/\/input[@name='username']<\/tt> (4) &#8211; <em>First input element with attribute named \u2018name\u2019 and the value \u2018username\u2019<\/em><\/li>\n<li><tt>\/\/form[@id='loginForm']\/input[1]<\/tt> (4) &#8211; <em>First input child element of the form element with attribute named \u2018id\u2019 and the value \u2018loginForm\u2019<\/em><\/li>\n<li><tt>\/\/input[@name='continue'][@type='button']<\/tt> (7) &#8211; <em>Input with attribute named \u2018name\u2019 and the value \u2018continue\u2019 and attribute named \u2018type\u2019 and the value \u2018button\u2019<\/em><\/li>\n<li><tt>\/\/form[@id='loginForm']\/input[4]<\/tt> (7) &#8211; <em>Fourth input child element of the form element with attribute named \u2018id\u2019 and value \u2018loginForm\u2019<\/em><\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.vskills.in\/practice\/selenium\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-93268 size-full aligncenter\" src=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Free-Practice-test.png\" alt=\"Selenium professional free practice test\" width=\"960\" height=\"150\" srcset=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Free-Practice-test.png 960w, https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Free-Practice-test-300x47.png 300w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><\/a><\/p>\n\n\n<p><a href=\"https:\/\/www.vskills.in\/certification\/tutorial\/selenium-certification\/\" target=\"_blank\" rel=\"noreferrer noopener\">Go back to Tutorial<\/a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href=\"https:\/\/www.vskills.in\/certification\/testing\/certified-selenium-professional\" target=\"_blank\" rel=\"noreferrer noopener\">Go to Home Page<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Selenium IDE | Locating by XPath XPath is the language used for locating nodes in an XML document. As HTML can be an implementation of XML (XHTML), Selenium users can leverage this powerful language to target elements in their web applications. XPath extends beyond (as well as supporting) the simple methods of locating by id&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"categories":[350],"tags":[384,7026,349,7027,6821,7025],"class_list":["post-800","page","type-page","status-publish","hentry","category-selenium","tag-locating-by-xpath","tag-selenium-automation-testing","tag-selenium-certification","tag-selenium-documentation","tag-selenium-professional","tag-selenium-webdriver"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Selenium Tutorials Selenium IDE | Locating by XPath<\/title>\n<meta name=\"description\" content=\"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Selenium Tutorials Selenium IDE | Locating by XPath\" \/>\n<meta property=\"og:description\" content=\"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T08:43:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/\",\"name\":\"Selenium Tutorials Selenium IDE | Locating by XPath\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\",\"datePublished\":\"2013-01-02T07:50:49+00:00\",\"dateModified\":\"2024-04-12T08:43:13+00:00\",\"description\":\"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png\",\"width\":750,\"height\":400},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Selenium Tutorials Selenium IDE | Locating by XPath\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Selenium Tutorials Selenium IDE | Locating by XPath","description":"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!","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:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/","og_locale":"en_US","og_type":"article","og_title":"Selenium Tutorials Selenium IDE | Locating by XPath","og_description":"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T08:43:13+00:00","og_image":[{"url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png","type":"","width":"","height":""}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/","name":"Selenium Tutorials Selenium IDE | Locating by XPath","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage"},"thumbnailUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png","datePublished":"2013-01-02T07:50:49+00:00","dateModified":"2024-04-12T08:43:13+00:00","description":"Learn about XPath. Make your resume stand out and become a Certified Selenium Professional. Try free practice tests here!","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#primaryimage","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2020\/12\/Certified-Selenium-Professional-16.png","width":750,"height":400},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/locating-by-xpath\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"Selenium Tutorials Selenium IDE | Locating by XPath"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=800"}],"version-history":[{"count":20,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/800\/revisions"}],"predecessor-version":[{"id":93482,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/800\/revisions\/93482"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}