Posts

Showing posts with the label XPATH

XPath Axis Family Tree Analogy

Image
  The major XPath axes follow family tree terminology: self::  is you. Downward: child::  are your immediate children. descendant::  are your children, and their children, recursively. descendant-or-self::  (aka  // ): are you and your descendants. Upward: parent::  is your mother  or  father. ancestor::  are your parent, and your parent's parent, recursively. ancestor-or-self::  are you and your ancestors. Sideways (consider elements earlier in the document to be younger): previous-sibling::  are your younger siblings, in age order. following-sibling::  are your older siblings, in age order. previous::  are your younger siblings and their descendants, in age order. following::  are your older siblings and their descendants, in age order. --------------------------------------------------------------------------------------------------------------------- child::  will select the immediate descendants of the ...

Handle custom tags using WebDriver

Sometime while doing automation we have to identify the element which have custom tags like <g> <svg> etc. For this we normally use * that will identify all elements tags in case we have to identify only specified custom tag then we can use below example for this. < svg height = "600" width = "910" xmlns : xlink = "http://www.w3.org/1999/xlink" id = "svgcontent" overflow = "visible" x = "910" y = "600" viewBox = "0 0 910 600" > < g style = "pointer-events:all" > < text fill = "rgb(0,0,0)" font - family = "Sans-Serif" font - size = "13" id = "80-155-126" transform = "rotate(-90, 168, 126)" y = "126" x = "168" style = " pointer - events : inherit "> A100A </ text > </ g > </ svg > Following Xpath will work here ...

XPath unable to find text with   or   using webdriver /

Hi, Some times we face issues to create XPath of  WebElement which have space in starting of it and then we check the element html source where we found &nbsp; or &nbsp is added before the element text while it display as space on UI. Normally we create the XPath to identify this element by adding space in the starting of it but his will not identify the element. There are another workaround to identify this element by contains text method. But if we have to identify the element with exact text having starting space or ending space  then we can use following way to do this. lets see this example <div class="myclass"> <label>AgendaShowCapacity &nbsp; </label> </div> OR <div class="myclass"> <label> &nbsp AgendaShowCapacity</label> </div> Following XPath will not work for this //label[text()='AgendaShowCapacity&nbsp;']  doesn't work Here we have to use follow...

WebDriver compare data/css between two pages

Hi All, In Web based project like implemented in CQ5 where we have to check same site for different country. For this we have to rollout/replicate some/all pages for different countries OR I can say downloaded/uploaded the production data in testing environment or vice versa. After this we have to validate page static data (like text) with production site Data, page wise validation. E.g.  One page of US site and replicate the same page for another country then verify page content or css For this we have to check manually, we can automate the same. I assume both pages having same text content (English). Logic to implement this: • First we have to analyze page objects properties (what are the common page objects (elements) properties are being used) like class, id, type etc and create array of this. • Then we have to get all elements from the base page(expected) using xpath(//*) • For each element get all properties and value using java script and store only those element...

Count elements/links on page using webdriver

Sometimes we need to count links on page. Here we are counting the elements on page. We use the same method for any type of element like link, span,button just use html tag of that element in xpath. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.net.URL; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By ; import org.openqa.selenium.WebDriver; import org.openqa.selenium. WebElement; import org.openqa.selenium.chrome. ChromeDriver; import org.openqa.selenium.firefox. FirefoxDriver; import org.openqa.selenium.firefox. FirefoxProfile;    

Locating elements using DOM, Css and Xpath

 Refer the below example Whole web page xpath=/html css=html document.documentElement Whole web page body xpath=/html/body css=body document.body All text nodes of web page //text() Element <E> by absolute reference xpath=/html/body/.../.../.../E css=body>…>…>…>E document.body.childNodes[i]...childNodes[j] Element <E> by relative reference //E css=E document.gEBTN('E')[0] Second <E> element anywhere on page xpath=(//E)[2] document.gEBTN('E')[1] Image element //img css=img document.images[0] Element <E> with attribute A //E[@A] css=E[A] dom=for each (e in document.gEBTN('E')) if (e.A) e Œ Element <E> with attribute A containing text 't' exactly //E[@A='t'] css=E[A='t']  Element <E> with attribute A containing text 't' //E[contains(@A,'t')]  Element <E> whose attribute A begins with 't' ...