Skip to main content

Different locators in selenium with examples

Types of Element Locators:

1| Html id | id attribute
2| Html name | name attribute
3| XPATH
4| Class name
5| CSS Selector
6| Link Text
7| Tag Name


XPATH

XPath is a way to navigate in xml document and this can be used to identify elements in a wen page. You may have to use XPath when there is no name/id associated with element on page or only partial part of name/IDE is constant.

Direct child - /
Relative child - //
id, class, names can also be used with XPath
//input[@name='q']
//input[@id='q']
//input[@class='q']
e.g., By.xpath(“//input[@id=’myElementId’]”)


CSS Selector

CSS location strategy can be used with Selenium to locate elements, it works using cascade style sheet location methods.in which -

Direct child is denoted with - (a space)
Relative child is denoted with - >
id, class, names can also be used with CSS
css=input[name='q']
css=input[id='q'] or input#q
css=input[class='q'] or input.q
e.g., By.cssSelector(“h1[title]”)


Link Text

e.g.,
By.linkText(“your text”)
By.partialLinkText(“your text”)

Comments

Popular posts from this blog

Rational Functional Tester: Calling RFT scripts from using xml tags

Hello, This will help to call RFT scripts in xml, if anyone using 'ant' this will help them to embed code to invoke RFT scripts. <java classname="com.rational.test.ft.rational_ft" fork="true" maxmemory="1024m">         <classpath>         <fileset dir="C:\Program Files\IBM\SDP\FunctionalTester\bin\">         <include name="rational_ft.jar" />         </fileset>         </classpath>         <jvmarg line="-Drational_ft.install.dir=&quot;C:\Program Files\IBM\SDP\jdk_\jre\bin&quot;" />         <arg line="-rt.bring_up_logviewer false -datastore &quot;D:\RFT-Dev\Project&quot; -playback RFTTestSet5.testcase4.TestScript1" />         <arg line="-args -scriptArg ${scriptValue}" /> ...

Rational Functional Tester: Creating and Reading Datapool cell value in RFT

Hello, Hope this will help for my friends who is trying to use data pool for dynamic values.If you want to use any run time values in between scripts then you will be looking for the functions to read/write/create datapool cells dynamically. /************ Dp row count *************************/ IDatapoolIterator  ite; ite.dpCurrent().getEquivalenceClass().getRecordCount(); /***************** to set cell value **************/ IDatapoolIterator it; ((DatapoolCell) it.dpCurrent().getCell("RunTimeSheetForContainers")).setCellValue("Y"); /*********** to load CSV files (csv to Datapool)*******************************/ public IDatapoolIterator LoadCSV(String Sname)       {             File fname=getFileName(Sname);             IDatapool dp=DatapoolUtilities. loadCSV (fname, "," , true );  ...

Rational Functional Tester: Verify text in html page

 Steps: 1.        For existing script, go to   “Insert verification point” button 2.        In “Verification point and action wizard” Click on “Object finder” 3.        Select the text which u want to verify (read mark will be highlighted when u show) 4.        Next you are allowed to select action 5.        Select “perform Data verification” to verify text select “Perform propertied verification ” to verify properties 6.        Next , now u can see the text which u are setting as verification point(u can edit if u need)