Basic Selenium

How to write Dynamic XPath in Selenium

Welcome to Selenium tutorial, today we will see how to write Dynamic XPath in Selenium because we can’t go ahead without XPath and CSS so let’s discuss XPath different methods in detail. Selenium has 8 locators which include id, name, classname, XPath, CSS, linkText, partialLinkText and tag name which make our task easy to find elements.

Previously we have firebug and firepath in Firefox which helped us to find and locate XPath in a simple manner but now both are officially deprecated now we have very easy Chrome Extension called ChroPath which does the same job. I have a detailed video on this which talks about how to use ChroPath.

One more plugin to find XPath called XPath Checker but I love ChroPath

Even if you don’t want to use any plugin then still you can find XPath in chrome browser using the normal search box, for this as well I have a detailed video which talks about how to find XPath in chrome browser without any plugin.

Once you are done with XPath, I will highly recommend you to visit Dynamic CSS as well which is highly used in Cross-browser Testing as well.

 

                                     Here is the Youtube video for Dynamic XPath

 

 

 

Dynamic XPath in Selenium Webdriver

Relative XPath method

 

Using single attribute

// tagname[@attribute-name=’value1’]



Example

// a [@href=’http://www.google.com’]


//input[@id=’name’]


//input[@name=’username’]


//img[@alt=’sometext’]

And so on.

Dynamic XPath in Selenium

Using multiple attribute

//tagname[@attribute1=’value1’][attribute2=’value2’]



//a[@id=’id1’][@name=’namevalue1’]

//img[@src=’’][@href=’’]

 

XPath in Selenium1

 

And so on.

 

Using contains method

Syntax

//tagname[contains(@attribute,’value1’)]

//input[contains(@id,’’)]

//input[contains(@name,’’)]

//a[contains(@href,’’)]

//img[contains(@src,’’)]

//div[contains(@id,’’)]

And so on.

Dynamic Xpath in Selenium

Using starts-with method

//tagname[starts-with(@attribute-name,’’)]



//id[starts-with(@id,’’)]

//a[starts-with(@href=’’)]

//img[starts-with(@src=’’)]

//div[starts-with(@id=’’)]

//input[starts-with(@id=’’)]

//button[starts-with(@id,’’)]

And so on.

Dynamic XPath in Selenium

 

Using Following node

Xpath/following::again-ur-regular-path

//input[@id=’’]/following::input[1]

//a[@href=’’]/following::a[1]

//img[@src=’’]/following::img[1]

 Dynamic Xpath in Selenium

Using preceding node

Xpath/preceding::again-ur-regular-path

//input[@id=’’]/ preceding::input[1]

//a[@href=’’]/ preceding::a[1]

//img[@src=’’]/ preceding::img[1]

Dynamic Xpath in Selenium

Absolute XPath method

1-/html/head/body/div/input

 

Absolute-xpath

Absolute-xpath1

Text method in XPath

Syntax- tagname[text()=’text which is visible on page’]

Note- While using text() method make sure you provide the exact text else it will not match

Example //b[text()=’Admin’]

Text method in Selenium XPath

 

Text method with contains

Syntax- tagname[contains(text(),’partial text which you want to search ‘)]

Example – //*[contains(text(),’Employee Distribution by Subunit’)]

Text method with Contains method in Selenium XPath

 

                                               Relative and Absolute XPath method

//parent-xpath/absolute xpath

//input[@id=’section’]/div/input

 

Hope you are comfortable with XPath now. Please start writing XPath from your side and let me know if you are facing any issue.

For More updates Learn Automation page

For any query join Selenium group- Selenium Group

 

author-avatar

About Mukesh Otwani

I am Mukesh Otwani working professional in a beautiful city Bangalore India. I completed by BE from RGPV university Bhopal. I have passion towards automation testing since couple of years I started with Selenium then I got chance to work with other tools like Maven, Ant, Git, GitHub, Jenkins, Sikuli, Selenium Builder etc.

171 thoughts on “How to write Dynamic XPath in Selenium

  1. RANJAN V says:

    Nice Tutorial)))

  2. Narahari says:

    Detailed documentation with images. Very clear notes to note for dynamic xpath.
    Thanks a lot Mukesh ji

    1. Hi Hari,

      Thanks for your appreciation. Please feel free to ask your doubts and queries on my blog/youtube. I’ll try my level best to clarify it…:)

    2. kishore says:

      can u please help me how to write xpath for three dot button in an application

      1. Hi Kishore,

        Kindly share app URL for the same.

  3. Hitesh Chaudhari says:

    Hi Mukesh,

    Firsts of all thanks for the knowledge, it really helps me out with XPath. however, want your help in one scenario.
    i am dealing with multiple sites in loop and using following xpath to located and get clicked “About us” link.

    driver.findElement(By.xpath(“//a[text()=’About us’ or text()=’About Us’ or text()=’ABOUT US’ or text()=’about us’]”)).click();

    But in one site I got three elements using this xpath. No i wanted to clicked on second one. how do I do it

    Thanks,
    Hitesh Chaudhari

    1. Hi Hitesh,

      You can use above xpath with indexing like (//a[text()=’About us’ or text()=’About Us’ or text()=’ABOUT US’ or text()=’about us’])[1] OR (//a[text()=’About us’ or text()=’About Us’ or text()=’ABOUT US’ or text()=’about us’])[2]

  4. Nikhil says:

    Hi Mukesh can you please tell me difference between css and xpath ? which is faster and why? among all 8

    locator ?which we should we prefer under which scenario.

    Thanks in advance

    1. Hi Nikhil,

      CSS always traverse forward while xpath can traverse both
      Xpath engine is different for different browsers while CSS remains same
      Moreover, IE doesn’t has its native xpath engine due which CSS works works well on IE

  5. Anil Rautela says:

    Hi Mukesh,

    I want to pass variable to my contains(text(),’ ‘) method. For example,

    String organization=excel.getOrg(“Org_Net_Name”, 1, 0);
    driver.findElement(By.xpath(//div[contains(text(),’Visible Text’)]).click(); so here I dont want “Visible Text”, I want to pass “organization” which I have stored in String variable.

    How will I do this? Please share the code.

    1. Hi Anil,

      String VisibleText = “organization”;
      Then use it as driver.findElement(By.xpath(“//div[contains(text(),’”+VisibleText+”’)]”)).click();

  6. Pooja says:

    Hi,

    How to find xpath for the following case which contains href and class ng-ngbinding alone

    1. Hi Pooja,

      Go with //*[@href=’‘ and @ng-binding=’‘]

      1. pooja says:

        Thank you 🙂

        1. You’re welcome…:)

  7. Shivang Pathak says:

    Hi Mukesh,

    Can you please keep more details for ” Relative and Absolute XPath method” because most of the time testers have been facing the issue to find this time of Xpath.

    Thanks
    Shivang

    1. Hi Shivangi,

      Selection of property attributes while creation of relative xpath solely depends on stability of corresponding property as there is no strict guidelines for creation of xpaths. You will learn more sophisticated way of xpath creation as long as you keep on practising it. You can use chropath extension/addon in order to verify xpath which you are creating.

  8. viki says:

    how can I capture the xpath by mouse click in chrome

    1. Hi Viki,

      Could you please elaborate it…

  9. Jyothi says:

    Dear sir
    If I want to insert data by clicking add row and the textbook box differ by index and I want to read data from Excel..

    1. Hi Jyothi,

      You can all achieve these by single looping mechanism. Customize your xpath in such a way that it should accept index value with iteration number and same should be used to read data from excel too.

  10. kaustubha says:

    Hi Mukesh,

    Can we do Control+f to search for something or click F3 using python3 selenium? or can we get access to all window actions or keyboard actions? If you have any solution (workable solution) then please let me know I tried my ways none of them are working.

    1. Hi Kaustubha, Actions class can help you to automate all keyboard events.

  11. SATVEER BAJWA says:

    Hi Mukesh,
    Thanks for your guidance, I have different scenario in my webpage there is one element called builder where we edit our pictures and add any text, stickers on it or so on , I was trying to get the xpath of textbox that let say textbox is layer on the picture. How can I locate that layer in selenium . I have been trying since long time but I am not getting any help . please guide me accordingly.

    1. Hi Satveer,

      Now a days, market is full of different types of ui components and libraries so without looking and working on web ui of application, I can’t provide any solid solution for this. Follow what exception/ error you are getting and try to find solution for same.

      1. SATVEER BAJWA says:

        Okay Thanks a lot Mukesh. I will try to find solution . Thanks again

  12. cyrus says:

    Hi Mukesh,
    This is regarding the contains method that is used to locate element from the First Video timed at around 16:08, I guess you were writing the syntax incorrectly. I wrote the below and it found the title text:
    //input[contains(@name,’post_title’)]

    1. Thanks Vijay 🙂 I will update my post as well.

  13. Satwik says:

    No Mukesh my question was that in tags field in the UI that is the GUI there is also a text area so when you are writing the xpath it is showing one matching node, does that mean it is within one div tag and all the other fields like TITLE and it’s corresponding text area and TAGS and it’s corresponding text area are under independent and separate divs?

    Please share me the link to this site and Uname and password Mukesh, I could not get the link. Thanks in advance!

    1. Hi Satwik,

      In application which I used, there was only one textarea, all others were input box only and that was the reason it was showing one maching node. If there were more than one textareas in UI then I could gone with other attributes too.
      textarea tag can come under div tag also, as it depends UI component design.

  14. Satwik says:

    In the second video of xpath after content you are looking for textarea right? But the one next to TAGS label in the UI is also has a textarea, so why is it not being shown or is getting reflected in the following command? It should have shown two then right?

    1. Hi Satwik,

      Good observation but let me explain this… There were two same words, content & Content. First one was attribute of id and next one was actual text. Both are different. And you should also remember one more thing which is, creation of dynamic xpath is always case sensitive

  15. Jeby says:

    Hi Mukesh,

    I have fetched a alphanumeric character and stored In a string. It doesn’t have any white characters when it is stored in a string. However when I try to pass it through dynamic xpath like, //*[text()='” + string +”‘], the strings takes some white char in bEgiNniNg and end and it cannot find the xpath. How can I solve the issue?

    1. Hi Jeby,

      This xpath looks good only. Kindly check your code once again…

  16. Anjana says:

    Thank You, Mukesh,

    I did till //a[test()=’ABC’]/[1] but was not getting any matching results. I tried many times but not getting the element what I was looking for but () worked like magic.

    Thank You again.

    1. Hi Anjana,

      You are always welcome…:)

  17. Anjana says:

    Hi Mukesh,

    How can I write the XPath for the element which is n number of matching result and I want to select only the one(The first one)?

    For example, There is an n number of listings and all listings are having an edit option. How can I select the first one?

    1. Hi Anjana,

      Call driver.findElements which will return you list of webelements then iterate to required one
      Or
      Use indexing in xpath iteself like you have this dynamic xpath *//a[text()=’ABC’] which matches to multiple elements now use (*//a[text()=’ABC’])[1] to get first element

  18. Ashwini says:

    Hi Mukesh,
    This tutorial is really very helpful and covered all the important topics. But I need more clarification on Relative and Absolute Xpath.

  19. Shabana says:

    Thank you so much for ur beautiful explanation. it’s helping me a lot……

    1. Hi Shabana,

      Thanks for your appreciation. Stay tuned to my new blog posts…:)

  20. Jayshree Gadhave says:

    I start with web elements locator but it found quite difficult to guess the xpath is correct or not without firepath. As latest version not support the firepath. can u suggest the way that I can use to enter xpath and on same screen it shows the correct match or not.

    1. Hi Jayshree,

      You can use ChroPath addon for firefox

  21. Mandeep says:

    HI, I have cliked on Edit button on my screen .But the Treaty Excess Id is changing everytime .
    Please find the below Html.Could you please help me in finding xpath

    edit

    1. Hi Mandeep,

      Please mention the url correctly because mentioned url is not pointing to correct page.

  22. savita says:

    HI mukhesh ji
    You are god of selenium.Thanku so much.it helped me a aloot.Is there any way to find out xpath in IE browser.

    1. Hi Savita,

      Very soon I’ll upload a video tutorial for this.

  23. vinod singh says:

    Hi Mukesh,
    This post is amazing and very helpful. Can I write xpath in IE or Chrome browser like we do in Firefox browser?

    1. Hi Vinod,

      Yes, you can write and validate your dynamic xpath in Chrome and IE. But its not easy just like we find same using FirePath in FF.
      For Chrome, 1. Enabling Developer tool, do Cntrl+F keyboard action. After this, you can see one input bx at bottom of developer tool. In that input box, test your dynamic xpath over there.
      2. developer tool, enable console then type your dynamic xpath enclosed in $x() like this Sx(“//input[@value=’q’]”). Now press enter and matching results will come up in console itself
      For IE, you can visit this link http://westciv.com/mri/

  24. vyshak says:

    Hi Mukesh,

    I just started learning selenium through ur blogs. Now i am facing issue like duplicate ID name. I want to take value from Task Owner. Can u help me???

    Status:



    Task Owners:

    1. Hi Vyshakh,

      I can’t see any html stuffs over here.

  25. Naira says:

    Hello Mukesh. Thank for Your blog, because I’m a beginner and it really helps me.
    Could You please to write down a little about text() methods, because in the video above in some cases syntax was contains(text(), ‘something’), in the others contains(text()= ‘something’). I didn’t get.
    Thanks

    1. Hi Maruti,

      text() function always looks for exact matching of text while contains(text(),”) doesn’t look for exact matching text.

  26. vinod singh says:

    Hi Mukesh,

    Thank you for such a nice blog. it is really helpful for me.

    1. Hi Vinod,

      Thanks for your comments.

  27. Lee says:

    Hi Mukesh

    Let say you have a multiple ‘Browse…” on the same page. But, the id is dynamic. Everytime you log into that session. So, how would I be able to define the correct button of “Browse…”?
    The only way is by something that is calls array> How does that works?
    Example:
    ==$0

    1. Hi Lee,

      Yes, you can use array for that. Take all locators wrt browse button inside an array and call its click action based on index. Or you go for dynamic xpath.

  28. aridevi says:

    Very Informative and nice blog

    1. Hi Aridevi,

      Thanks for your comments.

  29. Ravi Gavkare says:

    Hello Mukesh,
    Thanks for uploading such a nice and useful selenium webdriver inforamtion.

    I have one query about dynamic xpath-
    I have following scenario :
    Click on + Add button then it will add new row in the table.
    Now here whatever new row added in the table then its hard to find xpath.

    Second thing i want to add multiple dynamic xpath and want to enter text.

    Please suggest some solution.

    1. Hi Ravi,

      If you are able to locate + button using xpath then after click on button, try dynamic xpath like //button[text()=’+’]/following::tr[1] to get first row. In similar fashion, you can proceed with other rows. This is just an example to navigate. Actual xpath on your application might differs.

  30. Sandeep Rapaka says:

    Hi Mukesh
    Very helpful thank you for your blog.

  31. Kevin R. Mariano says:

    Hi Mukesh,

    How does this work if the ID is continuously changing?
    I’m talking specifically about Salesforce.

    You’re method worked for the first run, no doubt. But when we got the new push(release), all the id changed and script failed.

    Do you recommend any unique approach to handle dynamic changes for automating Salesforce UI with Selenium Webdriver ?

    1. Hi Kevin,

      Interesting question 🙂 In this case you can take label name and then following tag. You also have to check the pattern of locator which can be changed and which can not. Based on that we need to decide which kind of xpath we will write.

  32. Aklakh Ahmad says:

    Hi Mukesh,
    There is multiple card in single page having unique tag name value but the place/sequence of changing dynamically. How to capture particular card?
    Thanks

    1. Hi Aklakh, You can use text and indexing as well if multiple matches are found.

  33. Ankit Nigam says:

    Hi Mukesh,

    I need to find svg class element locator. I tried multiple combination but can not go inside the svg class. Can you please help me here how to find svg class locator?

    1. Hi Ankit,

      Any example for this?

  34. Vikas says:

    Hi Mukesh

    Great tutorials. Keep up the good work man. Cheers.

  35. Devi says:

    Hi This is Devi. Your Answers are very good. Can u please help me? related to project in selenium. And actually happens in the real time project. I know manual and selenium concepts but how to implement those concepts in real time project give and explain one project.

  36. Google verification and Capcha code cant be automated

  37. sangeeta says:

    very happy …it helped me
    thank you mukesh

    1. sangeeta says:

      Hi mukesh …
      I have a question ..
      In our comapny, they told to use Automation (selenium) for regression testing first time and don’t have senior automation testers to guide . I know selenium webdriver but…how to implement all techniques in a real time project….how to verify valid and invalid values with error messages, completely.
      I felt instead of writing the codes and spending the time with exceptions,it is better to do manual testing very fast………
      Please guide me …
      Even though I know selenium and written script, but don’t know how to use it in real time project with some techniques….
      …….Everybody will explain basic execution using,find element,XPath concept,testng,Junit…..
      but I want to know, how to use which technique in which situation
      I don’t have hands-on experience much…

      Hope you will reply….
      Thank you

      1. Hey Sangeeta,

        I can understand your point but before my next answer first go through below post and video

        https://vistasadprojects.com/mukeshotwani-blogs-v2/base-class-in-selenium-webdriver/

        Once you are done then let me know.

  38. Ranjith Samalla says:

    Hi Muskesh,

    https://www.makemytrip.com/flights
    Im trying to handle Make my trip site Flights/ Domestic tab there is no Id, name or class
    i used
    1)//*[contains(@href,)]

    2)a[starts-with(@href=”//www.makemytrip.com/flights”)]
    3) //a[@href=”//www.makemytrip.com/flights”]/following::a[1]
    these are adentifying still 3 matching nodes can u pls let me how can i adentify Flight/Domestic tab

    1. This is perfect one match //img[@class=’mmt_header_logo’]//following::*[text()=’flights’]

    2. Atish Kadu says:

      Hi Ranjith,

      You can try this one.

      1. //a[@href=’//www.makemytrip.com/flights’]
      2. //a[contains(text(),’domestic’)]

      If you want to fetch the href attribute then
      //a[contains(text(),’domestic’)]/@href

      Thanks,
      Atish

      1. Ranjith Billakanti says:

        Thanks Atish.

  39. Rajani says:

    Hi Mukesh ,

    Id’s are getting changed dynamically in My application , I.e We are Creating Multiple Users, while login in to the application we need to verify an Image so the image id is getting changed User to user then how can i proceed(Here we dont have any text area to use Conatins or Starts-With)

    As shown below:

    can u please suggest a solution for this

    1. Hi Rajani,

      We have multiple options to check. Check if classname, alt text, position, src and so on will help you to verify the same.

  40. Sridhar says:

    HI Mukesh,

    How to write Relative xpath if two nodes are matching ,
    Example Two nodes:
    Node1:

    Belagavi (IXG)

    Node2:
    Belagavi (IXG)

    i want to click on first node , how to write relative xpath??

    1. Hey,

      In this case you can use Index as well driver.findElements(By.xpath(“ur_xpath”)).get(0).click();

    2. Sridhar says:

      Hi Mukesh,

      I got empty string when i use gettext() method while printing text from dropdown in Chrome….. Can please help me to find solution for this? Please see the below code which i used…

      ArrayList al= (ArrayList) driver.findElements(By.xpath(“//ul[@id=’DDL_Icon_listbox’]/li/*[@class=’selected-value’]”));
      for(WebElement we:al)
      {
      System.out.println(we.getAttribute(“innerText”));
      }

      1. Hi Sridhar,

        Try below

        old System.out.println(we.getAttribute(“innerText”));

        new System.out.println(we.getAttribute(“innerHTML”));

  41. swamil says:

    Hi Mukesh,

    i have been following most of your Videos on You Tube and learnautomation site,your explanations are too good.

    When can we expect tutorial on collections…like list,set,Queue .

    1. Will try my best for upload rest.

  42. Gaurav Khurana says:

    One of the best tutorial. I am not sure why i was away from it for so many days. Found it on Quora. Thanks Keep sharing the great things.

    It would be good to include CSS selector as well.
    for example
    css=a#id
    css=a.classname

  43. pooja pilkhwal says:

    hi mukesh
    can you please tell me how to handle dynamic id .
    Scenario:-create one folder under one folder upload 50 files.
    every time when we upload files ,id will be change .now that time i note all file id in excel after that one -by-one file will be scheduled .so.how can handle id in code .

    1. Hi Pooja,

      Yes you can need to add all concepts now 😉 Have you tried this from your side? What is the problem you are facing?

  44. Vaishali says:

    Hi Mukesh,

    Thanks a lot for sharing of Selenium which is so informative and very helpful.

    Can you help me,

    In my application the tabs which are used are dynamically changing and have to use SkipException but, i am not able to apply it.

    Example :- Billing Manager, Claims Manager, Insurance and so on…

    sometimes “Insurance Tab” is not in use.

    Please, if you can help me, it will be a big help.

    Thank You ..waiting for your reply.

    1. Hi Vaishali,

      Can you try below code

      @Test
      public void test2()
      {

      boolean status=driver.findElements(By.xpath(“ur xpath will come here”)).size()<=0; if(status) { System.out.println("=====Skiping test===="); throw new SkipException("=======Tab is not enabled so skipping the test========"); } }

      1. bhaskar says:

        Hello Mukesh,

        I am new to selenium , I was referring you Facebook test to verify various element . I couldn’t able to verify day , month and year element. Can you please help me on this .

  45. Ranjith Billakanti says:

    Hi Mukesh,

    Thanks for your posts, your posts are more informative, i am facing issues for one field to uniquely identify. could you please provide solution for this pls.
    details:
    Field name : Vendor
    Attributes :
    when i modfiy xpath as //input[@name=’C_BPartner_ID’] it is matching with 4 nodes
    and tried with multiple attributes using “And” operation as well.

      1. Ranjith Billakanti says:

        Thanks Mukesh.

  46. suraj says:

    Add text method also it will be helpful.
    //*[text=’my account’]
    //a[contains(text(),’logout’)]

    1. Hi Suraj,

      Correct I will add. Thanks

  47. VDS Anusha says:

    Thank you so much mukesh for uploading this video. It’s really awesome, after watching this video i got clearance o xpath

    1. Thanks Anusha, I am glad to know it helped you 🙂

  48. ashok mandadi says:

    Hi mukeh,
    Good afternoon,
    I am new in testing tools,i am learning manual+selenium but i can follow your site and i learn lot of things in your site,
    Is it possible to upload manual testing then can learn very fastly like doubts something like this.

    1. Hi Ashok,

      Yes I have planned for manual testing as well. I will try my best to upload soon.

  49. Neeraj Attri says:

    Hi Mukesh Otwani,
    //tagname[@attribute1=’value1’][attribute2=’value2’] i think second attribute should start with @ .

    1. Yes Neeraj correct let me update the same.

  50. Ashim Paudel says:

    Thanks for the awesome tutorial. I have been stuck with my selendroid automation coz I could not figure out how to combine two attributes. Saved my day….

    1. Hey Ashim,

      Cheers 🙂 and I am glad to know that you liked xpath post

  51. sudhr says:

    //a[contains(.,’Selenium’)])[1] plz explain this?

    1. It means find all elements which contains Selenium and get first element.

  52. Divya says:

    hey Mukesh

    very informative blog, can you please tell me how to find the xpath of last input field using last() or count() function?

    I have used following code, but it dint work

    //input[@type=’checkbox’][last()]

    regards
    Divya

    1. Hey Divya,

      There are two solutions for this.

      Solution 1-
      use following and then take last element using index

      Solution 2-

      driver.findElements(By.xpath(“//input[@type=’checkbox’]”));
      This will return list of checkbox then you can perform on last checkbox

      check below post for more details.
      https://vistasadprojects.com/mukeshotwani-blogs-v2/difference-between-findelement-and-findelements-in-selenium-webdriver/

  53. lalitha says:

    Hi Mukesh,

    it`s really a nice session given by you and easy to understand even.
    Thanks! Keep posting nice sessions like this. presentation was so nice 🙂

    1. Thanks Lalitha 🙂

  54. Soniya Vijaywargi says:

    Hi Mukesh, I am new to Selenium and I must say your blog is awesome. I am refering this blog for my learning. Keep posting!!!

    Thank you so much.

    1. Hey Soniya,

      Your most welcome and Please let me know if any help required from my side 🙂

  55. Arun says:

    Hi Mukesh,

    I am following all your blogs on selenium and it is really helpful.
    I always get one question in interview. what is that challenging task you have done in selenium. I really don’t know what to answer. I am a beginner in selenium. Could you help me with some examples I can try out which quite challenging to be done in selenium

    1. I will share doc with you that will contain all the answer

      1. sandeep says:

        Hi Mukesh ,can you please share that doc with me also(sandeepmalik340@gmail.com) . Thanks in advance

        1. Hey Sandeep,

          join my email list and you will get answers in your email 🙂

      2. Naveen says:

        Hi Mukesh,

        I started referring your blog from the last week and The informations are very much useful for me. I am beginner in selenium, I am learning for the past 2 months. could you please me the doc which you shared with Arun. So that I will prepare for my interview,

        Thanks!! Keep posting:)

  56. Sanjeev Gautam says:

    Hello sir,
    I can’t able to login on http://www.demosite.center/wordpress/wp-login.php
    with user id: admin & Password : demo123
    It’s showing 404 error

    1. Hey Sanjeev,

      Above site has some issues.
      Kindly use below url for demos.

  57. Satheesh says:

    Hi,

    Could you please help me on my problem,

    When I am writing xpath in fire bug and it matches perfectly with the node. But if i am using in eclipse i am getting a exception – NoSuch Element Expection.

    I Have used wait conditions as well.. Waiting for your reply.

    Thanks,
    Satheesh

    1. Hey Satheesh,

      Chances are high that element will be inside frame, kindly cross check.

  58. Anika Mittal says:

    Sir,
    I wanted to know how to find xpath when your id is continuously changing. I mean last xpath doesn’t work any more. Element not found error is arising at every run.
    Please help. It’s urgent.

    1. It works for me always.

  59. sharayu says:

    Hi, I am trying to locate the url for topmost ad link (first line) and click on it. The ad link comes in iframe and there is no good locator for which i can find element; as all the ids keep changing for every new search and class names have space in their name which doesnt evaluate in firepath. could you please help me in locating xpath or any other locator.

    1. any other example?

  60. Mayank says:

    Hi Mukesh

    I found your website quite helpful in learning selenium xpaths.
    Thanks for sharing such a great information.

    I want to tell you that I am facing a problem while handling xpath which is dynamic.

    Basically the task I am trying to perform is :

    open snapdeal.com

    search external hard disk

    add to the cart(any hard disk)

    Now when I am trying to increase the quantity of hard disk in cart and I am not able to do that.

    The xpath of drop down list value keeps on changing.

    I also asked few experts..they were also not able find the solution.

    I request you to help me out.

    Thanks

    1. HI Mayank

      Try below xpath

      //select[contains(@class,’item-quantity customized’)]

  61. aakash says:

    Hey I want to pick all packages on http://www.tripfactory.com/.can anyone provide me the possible xpath?

    1. Hi Akash,

      is it fixed?

  62. Abhijeet says:

    Hi Mukesh,
    How we use Ends-with in xpath?

    1. Hi Abhijeet

      use contains in this case.

  63. Prasad says:

    Really awesom article.
    Thank you for sharing information.

  64. prathap says:

    Thanks a lot for your great effort .it is understandable very easily.Seriously it is an ultimate blog liked it

    Thanks a lot
    Prathap

    1. Thank you pratap. I am glad to know that you liked it. Keep visiting.

  65. Sandhya says:

    Hi Mukesh,

    i faced this question interview.For Example in flipakart Application i choose one item and payed amount for that item.after that we will get one Reference no.i want to copy and paste that number in desktop note pad? how We can do?By using Auto it we can do it or any other procedure is there please let me know

    Thank you in advance

    1. Hi Sandhya,

      where you are getting stuck please let me know. Using AutoIT and Sikuli we can do.

  66. satish narayana kakimukkala says:

    i got clear idea about xpaths……….. thank u so much mukesh otwani sir..

    1. Hi Satish,

      Thank you. Please share with your friends as well.

  67. Jai Prakash Keswani says:

    Is it a correct xpath ?

    .//a[@id=’top’][contains(@href, ’add/product/1/’)]

    1. Hi Jai,

      Check if it is highlighting element then its correct.

  68. yashika says:

    Hi Mukesh,

    Thanks for sharing your intense knowledge about it.

    Thanks,
    Yashika.

    1. Thanks Yashika,keep visiting and check other articles too.

    2. Nagaraj Byndoor says:

      Hi Mukesh,

      Thanks for sharing knowldge.

      Thanks,
      Nagaraj

      1. Your most welcome Nagaraj

  69. bhaskar says:

    i have faced this question in the interview. in an app. there are three obj. named a,b,c,.under each object there is button named ADDTOCART .and i want to press the ADDTOCART button(under object c only.not a and b).is there any way to click on button by only seeing the element.

    1. Hi Bhaskar,

      You can do using following method of xpath. Fist find add to cart button then using following get all button and then get the first one only.

  70. bhaskar says:

    is there any way to write x path only by seeing the element

    1. Yes but for some element not for all.

  71. Anjali Aswani says:

    Hi Mukesh

    Thanks for sharing your wide knowledge in Xpath.
    The way you have explained was very much easy for us to understand.

    Thanks

    Anjali

    1. Hi Anjali,

      Thank you glad to know you liked it 🙂

      Keep visiting

  72. Srikanth says:

    It was good intormative…Thanks

    1. Thanks Srikanth 🙂

  73. Sandeep says:

    Slower Pace and example based session. I have gone 1 step up in my xpath knowledge. thanks 🙂

    1. Thanks Sandeep 🙂 Glad to know it helped you. Keep visting.

      Happy weekend.

  74. Nur says:

    nice one man, keep going on

  75. sairam says:

    Hello Mukesh,

    The tutorials you posted was very useful and very informative.

  76. Omar says:

    very informative.
    Thank you

    1. Hi Omar,

      Thanks 🙂

  77. Satyanarayan Panigrahi says:

    Hi Mukesh….i am a big fan of you…

    Kindly share some post regarding how to handle a element using regular expression that changes regularly.

    1. Mukesh Otwani says:

      Hi Satyanayan,

      Thanks a ton for such a nice comment.

      I generally use start-with and contains method for handling dynamic element.

      Example if i have one field like username567 and when i reload page id change to username787 so in this you can use above xpath technique.

      Hope its clear 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.