Posts

Showing posts with the label Locating elements

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' ...