{"id":370,"date":"2013-10-25T05:25:46","date_gmt":"2013-10-25T05:25:46","guid":{"rendered":"http:\/\/codethataint.com\/blog\/?p=370"},"modified":"2013-11-11T06:42:21","modified_gmt":"2013-11-11T06:42:21","slug":"selenium-notes1","status":"publish","type":"post","link":"https:\/\/codethataint.com\/blog\/selenium-notes1\/","title":{"rendered":"Selenium Notes1"},"content":{"rendered":"<p><strong>How to find particular text in web driver method<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nWebDriver driver = new FirefoxDriver();\r\ndriver.get(&quot;https:\/\/localhost:8080\/Login&quot;);\r\n\r\n\/\/Finds the xpath of element which contains UserName\r\nWebElement strElemnt1 = driver.findElement(By.xpath(&quot;html\/body\/div&#x5B;1]\/div&#x5B;2]\/div&#x5B;2]\/div&#x5B;2]\/p&#x5B;1]\/b&quot;));\r\n<\/pre>\n<p><strong>How to get Last Row in Table <\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/How to get Last Row in Table \r\nString cssLast=&quot;table&#x5B;class='dataTable']&gt;tr:first-child&gt;td:last-child&quot;\r\nString cssFirst=&quot;table&#x5B;class='dataTable']&gt;tr:last-child&gt;td:last-child&quot;\r\n\r\ndriver.findElement(By.cssSelector(cssLast)).getText();\r\ndriver.findElement(By.cssSelector(cssFirst)).getText();\r\n<\/pre>\n<p><strong>By Using XPath<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/By Using XPath\r\nWebElement lastCellInFirstRow = driver.findElement(By.xpath(&quot;table&#x5B;@class='dataTable']\/\/tr&#x5B;1]\/\/td&#x5B;last()]&quot;));\r\nWebElement lastCellInLastRow = driver.findElement(By.xpath(&quot;table&#x5B;@class='dataTable']\/\/tr&#x5B;last()]\/\/td&#x5B;last()]&quot;));\r\n\r\n<\/pre>\n<p><strong>How to detect custom attribute <\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/How to detect custom attribute \r\nassertTrue(selenium.isElementPresent(&quot;\/\/*&#x5B;@btn-tag-title='Sign In']&quot;));\r\nselenium.click(&quot;\/\/*&#x5B;@btn-tag-title='Sign In']&quot;);\r\n\r\nassertTrue(selenium.isElementPresent(&quot;css=*&#x5B;btn-tag-title='Sign In']&quot;));\r\nselenium.click(&quot;css=*&#x5B;btn-tag-title='Sign In']&quot;);\r\n<\/pre>\n<p><strong>Finding custom attribute of span where attr=&#8221;data-automation-id&#8221; and val=&#8221;SEL_ERR&#8221;<\/strong><\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\n\/\/HTML Code\r\n&lt;span data-automation-id=&quot;SEL_ERR&quot;&gt;\r\n  Error Description\r\n&lt;\/span&gt;\r\n\r\n\/\/Selenium Code\r\ndriver.findElement(By.cssSelector(&quot;span&#x5B;data-automation-id='SEL-ERR']&quot;));\r\n<\/pre>\n<p>If Selenium cannot find it, it&#8217;ll throw an exception. Exceptions are costly. You can use .findElements instead (mentioned in 1)), which will simply return an empty list if it cannot find the element you are looking for<\/p>\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\ndriver.findElements(By.cssSelector(&quot;span&#x5B;data-automation-id='SEL-ERR']&quot;)).size() != 0;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to find particular text in web driver method WebDriver driver = new FirefoxDriver(); driver.get(&quot;https:\/\/localhost:8080\/Login&quot;); \/\/Finds the xpath of element which contains UserName WebElement strElemnt1 = driver.findElement(By.xpath(&quot;html\/body\/div&#x5B;1]\/div&#x5B;2]\/div&#x5B;2]\/div&#x5B;2]\/p&#x5B;1]\/b&quot;)); How to get Last Row in Table \/\/How to get Last Row in Table String cssLast=&quot;table&#x5B;class=&#8217;dataTable&#8217;]&gt;tr:first-child&gt;td:last-child&quot; String cssFirst=&quot;table&#x5B;class=&#8217;dataTable&#8217;]&gt;tr:last-child&gt;td:last-child&quot; driver.findElement(By.cssSelector(cssLast)).getText(); driver.findElement(By.cssSelector(cssFirst)).getText(); By Using XPath \/\/By Using XPath WebElement lastCellInFirstRow&hellip; <a href=\"https:\/\/codethataint.com\/blog\/selenium-notes1\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,47],"tags":[],"class_list":["post-370","post","type-post","status-publish","format-standard","hentry","category-selenium","category-testing"],"_links":{"self":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/comments?post=370"}],"version-history":[{"count":9,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions"}],"predecessor-version":[{"id":379,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/posts\/370\/revisions\/379"}],"wp:attachment":[{"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/media?parent=370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/categories?post=370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codethataint.com\/blog\/wp-json\/wp\/v2\/tags?post=370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}