{"id":90572,"date":"2017-07-20T10:51:47","date_gmt":"2017-07-20T10:51:47","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=90572"},"modified":"2017-09-08T14:32:54","modified_gmt":"2017-09-08T14:32:54","slug":"element-locators-in-selenium","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/","title":{"rendered":"Element Locators In Selenium WebDriver"},"content":{"rendered":"<p>In the <a href=\"https:\/\/webkul.com\/blog\/getting-started-selenium\" target=\"_blank\" rel=\"noopener noreferrer\">previous<\/a> blog we learnt how to\u00a0<a href=\"https:\/\/webkul.com\/blog\/getting-started-selenium\" target=\"_blank\" rel=\"noopener noreferrer\">configure Eclipse with selenium<\/a> and to create an environment where we can start write some script.<br \/>\nConsider we are writing a selenium script to open a website (say webkul.com). Now, how to verify if the page opened at the execution is of webkul itself. Is it the same page we were looking for? To achieve this, we need to find some elements in page which verifies that it is correct. We have different element locators in selenium to locate elements and perform actions like &#8211; click, type, select etc. So, knowledge of element locators is necessary to work with selenium.<br \/>\nBelow are the locators which are supported by selenium :<\/p>\n<ol>\n<li>By ID<\/li>\n<li>By Name<\/li>\n<li>By Class Name<\/li>\n<li>By Tag Name<\/li>\n<li>By Link Text Or Partial Link Text<\/li>\n<li>By cssSelector<\/li>\n<li>By XPath<\/li>\n<\/ol>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">Locating Element By ID<\/h3>\n<\/div>\n<div class=\"panel-body\">\n<p>If a web application page has an element with unique and a static Id, we can locate that element by it\u2019s Id. For example, In the below image we have a search input with it\u2019s id as \u201csearch\u201d. Here, we will get the element by its id and will write a keyword which we wanted to search.<\/p>\n<p><strong>Driver.findElementBy.Id(\u201csearch\u201d).sendkeys(\u201cMarketplace for shopify\u201d);<\/strong><\/p>\n<div class=\"para-images\">\n<div><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\" alt=\"\" width=\"497\" height=\"262\" loading=\"lazy\" \/><\/div>\n<\/div>\n<p>Below example will show how to get element by it&#8217;s id and send some keys to that element:<\/p>\n<pre class=\"brush:java\">package elementById;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByID {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \/\/ setting the driver executable for chrome browser\r\n\t\tdriver = new ChromeDriver();\t\t\t\t\/\/ created a new instance for chrome driver\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementById() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/store.webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tdriver.findElement(By.id(\"search\")).sendKeys(\"MarketPlace for shopify\");\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<h3 class=\"panel-title\">Locating Element By Name<\/h3>\n<\/div>\n<div class=\"panel-body\">\n<p>When we locate an element by it\u2019s name, the web driver looks for name attribute specified by us. Finding an element by \u201cID\u201d or by \u201cName\u201d is same. The only difference is, for ID web driver looks element with specified ID and incase of Name it search for specified name.<br \/>\nIn the above example we found element by id. Lets get the same element via its attribute name instead of ID.<br \/>\n<strong><strong><strong>Driver.findElementBy.Name(\u201cq\u201d).sendkeys(\u201cMarketplace for shopify\u201d);<\/strong><\/strong><\/strong><\/p>\n<div class=\"para-images\">\n<div><a href=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-1-1.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-1-1.jpg\" alt=\"\" width=\"1230\" height=\"650\" loading=\"lazy\" \/><\/a><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<pre class=\"brush:java\">package elementByName;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByName {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \/\/ setting the driver executable for chrome browser\r\n\t\tdriver = new ChromeDriver();\t\t\t\t\/\/ created a new instance for chrome driver\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByName() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/store.webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tdriver.findElement(By.name(\"q\")).sendKeys(\"MarketPlace for shopify\");\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Locating Element By Class Name<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>We have seen how to locate elements by IDs and Name. But, what if an element neither has an ID nor a Name in its attribute? So, locating an element by its class name is a good choice when we don\u2019t have a ID or name to locate with.<\/p>\n<p><strong>Driver.findElementBy.ClassName(&#8220;logo&#8221;);<\/strong><\/p>\n<p>&nbsp;<\/p>\n<div class=\"para-images\">\n<div><img decoding=\"async\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-17-15-30-png.jpg\" loading=\"lazy\" \/><\/div>\n<\/div>\n<p>In the above image, we don\u2019t have any Id or name to locate the logo which contains \u201cWebkul Store\u201d. Here, we can see that the element has a class associated \u201clogo\u201d. We can use this class to get the text inside this element. Lets see the code below:<\/p>\n<pre class=\"brush:java\">package elementByClassName;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByClassNme {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \r\n\t\tdriver = new ChromeDriver();\t\t\t\t\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByClassName() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/store.webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tString logoText= driver.findElement(By.className(\"logo\")).getText();\r\n\t\tif(logoText.equalsIgnoreCase(\"webkul store\"))\r\n\t\t{\r\n\t\t\tSystem.out.println(\"We are at the home page of webkul store\");\r\n\t\t}else\r\n\t\t\tSystem.out.println(\"We are not at the home page of webkul store\");\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Locating Element By Tag Name<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>Till now, we have located elements using ID,Name and Class Name. Considering, if an element don\u2019t have an Id, Class and Name attribute. Here, we have another selector in selenium which looks for element\u2019s tag name in the web page.<br \/>\nAlthough, their are other selectors like xpath or css selector to look for elements with no id or name. We can also use tag name to find elements. This strategy is not much popular because in a web page there are many elements with same tag name. So, it would be difficult to get the tag we are looking for (a page could have\u00a0hundreds of elements with same tag).<br \/>\nIn the below image we have to click on drop-down to select the currency for the website.To get this we can use the tag name selector, perhaps, we can get this element by Id :<\/p>\n<p><strong>driver.findElement(By.tagName(&#8220;select&#8221;))<\/strong><\/p>\n<div class=\"para-images\">\n<div><a href=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-16-55-33-png.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-16-55-33-png.jpg\" alt=\"\" width=\"1294\" height=\"567\" loading=\"lazy\" \/><\/a><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The practical implementation foe selecting element by tag name is given below:<\/p>\n<pre class=\"brush:java\">package elementByTagName;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByTagName {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \r\n\t\tdriver = new ChromeDriver();\t\t\t\t\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByTagName() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/store.webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tString SupportedCurrenry= driver.findElement(By.tagName(\"select\")).getText();\r\n\t\tSystem.out.println(\"The currencies supported by webkul are :\\n \"+ SupportedCurrenry);\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}\r\n<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Locating Element By Link Text Or By Partial\u00a0Link Text<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>Suppose, we want to target a link and if you know the text under link area, the best selector we can use is By link text or By partial link text.<br \/>\nIf we are using Link text, we need to specify the full text and if we don\u2019t know the full link text then, we can use a part of link via partial link text.<br \/>\nIn the below image we have a link text as \u201dwe\u2019re hiring \u201c. Now, we will see the implementation by Link-text as well as by Partial-link text.<\/p>\n<p class=\"brush:java\"><strong>driver.findElement(By.linkText(&#8220;we\u2019re hiring&#8221;));<\/strong><br \/>\n<strong>driver.findElement(By.partialLinkText(&#8220;we\u2019re&#8221;));<\/strong><\/p>\n<div class=\"para-images\">\n<div><a href=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-19-29-06-png.jpg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"alignnone\" src=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-19-29-06-png.jpg\" alt=\"\" width=\"1296\" height=\"494\" loading=\"lazy\" \/><\/a><\/div>\n<\/div>\n<p class=\"brush:java\">Below is the implementation for using element by Link or partial link:<\/p>\n<pre class=\"brush:java\">package elementByLinkText;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByLinkText {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \r\n\t\tdriver = new ChromeDriver();\t\t\t\t\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByLinkText() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tdriver.findElement(By.linkText(\"we\u2019re hiring\")).click(); \/\/ we can use any \"linkText\" or \"PartialLinkText\"\r\n\/\/\t\tdriver.findElement(By.partialLinkText(\"we\u2019re\")).click(); \r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Locating Element by Css Selector<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>CSS is \u201cCascading Style Sheets\u201d, defined to display HTML in structured styles at the webpage. It is a combination of element selectors and selector value which identifies the element. If we don\u2019t have an option to select an element via Id or class, we can use css selector.<\/p>\n<p>Consider the first element (the search box), we located the input by Id. Now, lets see how can we do the same using Css Selector:<br \/>\n<strong><strong><strong>driver.findElement(By.cssSelector(&#8220;input[name=&#8217;q&#8217;]&#8221;));<\/strong><\/strong><\/strong><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"brush:java\">package elementByCssSelector;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByCssSelector {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \r\n\t\tdriver = new ChromeDriver();\t\t\t\t\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByCssSelector() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tdriver.findElement(By.cssSelector(\"input[name='q']\")).sendKeys(\"Marketplace for shopify\");;\r\n\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}<\/pre>\n<\/div>\n<\/div>\n<div class=\"panel panel-primary\">\n<div class=\"panel-heading\">\n<div>\n<h3 class=\"panel-title\">Locating Element By\u00a0Xpath<\/h3>\n<\/div>\n<\/div>\n<div class=\"panel-body\">\n<p>XPath is defined as XML path. We can find any element on the web page using XML path expression of that particular element.\u00a0It is most popular and best way to locate element in WebDriver.<br \/>\nBelow is a basic syntax of xpath experssion :<br \/>\n<strong>xpath=\/\/tagname[@attribute=&#8217;value&#8217;] <\/strong>, where<\/p>\n<ul>\n<li>\/\/ : Select node. (we use * to define anywhere(node) at the page)<\/li>\n<li>Tagname: Tagname of the particular node\/element.<\/li>\n<li>@: Select attribute.<\/li>\n<li>Attribute: Attribute name of the node. (eg: id, name, class)<\/li>\n<li>Value: Value of the attribute (eg: id= &#8220;id1&#8221; , name= &#8220;fname&#8221;)<\/li>\n<\/ul>\n<p>Lets write an xpath of an input element which have id=&#8221;search&#8221; in the whole page. It will be like<br \/>\n<strong>driver.findElement(By.xpath(&#8220;\/\/input[@id=&#8217;search&#8217;]&#8221;));<\/strong><\/p>\n<pre class=\"brush:java\">package elementByCssXpath;\r\nimport org.openqa.selenium.By;\r\nimport org.openqa.selenium.WebDriver;\r\nimport org.openqa.selenium.chrome.ChromeDriver;\r\nimport org.testng.annotations.AfterTest;\r\nimport org.testng.annotations.BeforeTest;\r\nimport org.testng.annotations.Test;\r\n\r\npublic class FindElementByXpath {\r\n\tWebDriver driver;\r\n\t@BeforeTest\r\n\tpublic void setUp() throws Exception {\r\n\t\tString chrome_path = System.getProperty(\"user.dir\")+\"\/chromedriver\";  \r\n\t\tdriver = new ChromeDriver();\t\t\t\t\r\n\t\tdriver.manage().window().maximize(); \r\n\t}\r\n\t@Test\r\n\tpublic void findElementByXpath() \r\n\t\t\tthrows InterruptedException\r\n\t{\r\n\t\tdriver.navigate().to(\"http:\/\/store.webkul.com\");\r\n\t\tThread.sleep(1000);\r\n\t\tdriver.findElement(By.xpath(\"\/\/*[@id='search']\")).sendKeys(\"Marketplace for shopify\");\r\n\r\n\t}\r\n\t\r\n\t@AfterTest\r\n\tpublic void tearDown() throws Exception {\r\n\t    driver.quit();\r\n\t}\r\n}<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In the previous blog we learnt how to\u00a0configure Eclipse with selenium and to create an environment where we can start write some script. Consider we are writing a selenium script to open a website (say webkul.com). Now, how to verify if the page opened at the execution is of webkul itself. Is it the same <a href=\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":94,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4312,3137,4932],"tags":[5159,5160,5164,5162,5180,5163,5165,5167,5168,5158,5161],"class_list":["post-90572","post","type-post","status-publish","format-standard","hentry","category-automation-testing","category-testing","category-web-testing","tag-element-locators-in-selenium","tag-find-element-in-web-driver","tag-locating-element-by-class-name","tag-locating-element-by-id","tag-locating-element-by-link-text-or-by-partial-link-text","tag-locating-element-by-name","tag-locating-element-by-tag-name","tag-locating-elements-by-css-selector","tag-locating-elements-by-xpath","tag-selenium-element-locators","tag-webdriver-element-locators"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Element Locators In Selenium WebDriver - Webkul Blog<\/title>\n<meta name=\"description\" content=\"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Element Locators In Selenium WebDriver - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-20T10:51:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-09-08T14:32:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\" \/>\n<meta name=\"author\" content=\"Himanshu Chand\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Himanshu Chand\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\"},\"author\":{\"name\":\"Himanshu Chand\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f\"},\"headline\":\"Element Locators In Selenium WebDriver\",\"datePublished\":\"2017-07-20T10:51:47+00:00\",\"dateModified\":\"2017-09-08T14:32:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\"},\"wordCount\":933,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\",\"keywords\":[\"element locators in selenium\",\"find element in web-driver\",\"Locating Element By Class Name\",\"Locating Element By ID\",\"Locating Element By Link Text Or By Partial Link Text\",\"Locating Element By Name\",\"Locating Element By Tag Name\",\"Locating Elements By Css Selector\",\"Locating Elements By Xpath\",\"Selenium element locators\",\"webdriver element locators\"],\"articleSection\":[\"Automation testing\",\"Testing\",\"Web testing\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\",\"url\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\",\"name\":\"Element Locators In Selenium WebDriver - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\",\"datePublished\":\"2017-07-20T10:51:47+00:00\",\"dateModified\":\"2017-09-08T14:32:54+00:00\",\"description\":\"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg\",\"width\":1230,\"height\":650},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Element Locators In Selenium WebDriver\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f\",\"name\":\"Himanshu Chand\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Himanshu Chand\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/himanshu-chand168\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Element Locators In Selenium WebDriver - Webkul Blog","description":"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..","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:\/\/webkul.com\/blog\/element-locators-in-selenium\/","og_locale":"en_US","og_type":"article","og_title":"Element Locators In Selenium WebDriver - Webkul Blog","og_description":"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..","og_url":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2017-07-20T10:51:47+00:00","article_modified_time":"2017-09-08T14:32:54+00:00","og_image":[{"url":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg","type":"","width":"","height":""}],"author":"Himanshu Chand","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Himanshu Chand","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/"},"author":{"name":"Himanshu Chand","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f"},"headline":"Element Locators In Selenium WebDriver","datePublished":"2017-07-20T10:51:47+00:00","dateModified":"2017-09-08T14:32:54+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/"},"wordCount":933,"commentCount":1,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg","keywords":["element locators in selenium","find element in web-driver","Locating Element By Class Name","Locating Element By ID","Locating Element By Link Text Or By Partial Link Text","Locating Element By Name","Locating Element By Tag Name","Locating Elements By Css Selector","Locating Elements By Xpath","Selenium element locators","webdriver element locators"],"articleSection":["Automation testing","Testing","Web testing"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/","url":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/","name":"Element Locators In Selenium WebDriver - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage"},"thumbnailUrl":"https:\/\/webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg","datePublished":"2017-07-20T10:51:47+00:00","dateModified":"2017-09-08T14:32:54+00:00","description":"Consider we are writing a selenium script to open a website (say webkul.com). How will we verify if the page opened at the execution is of webkul its..","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/element-locators-in-selenium\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#primaryimage","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2017\/07\/Screenshot-from-2017-07-27-15-10-10-png-2.jpg","width":1230,"height":650},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/element-locators-in-selenium\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Element Locators In Selenium WebDriver"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/08d4d0b31f228925099740afd668b50f","name":"Himanshu Chand","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/067d10770fdcc86d177164f68eb74b9528397b3a5fbf01970b6f6dfd48c64281?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Himanshu Chand"},"url":"https:\/\/webkul.com\/blog\/author\/himanshu-chand168\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/90572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=90572"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/90572\/revisions"}],"predecessor-version":[{"id":95502,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/90572\/revisions\/95502"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=90572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=90572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=90572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}