Search code examples
selenium-webdriverxpathautomationcss-selectors

Dynamic website https://demo.guru99.com/test/web-table-element.php - How to find Xpath


https://demo.guru99.com/test/web-table-element.php

How to find XPath? Dynamically how to get XPath for changing values, get current price for company that starts with letter A in the above mentioned url. Table changes dynamically.

//a[contains(text(),"Apollo Hospitals")]

Solution

  • Below XPath expression is what you need:

    //table[@class='dataTable']//td[1]//text()[starts-with(normalize-space(), 'A')]//following::td[3]
    

    Explanation: This XPath expression locates the Current Price of the Company which starts with letter A.

    Let me try to explain part by part:

    • Part 1. //table[@class='dataTable'] - Locate the table element with attribute=class and value=dataTable

    • Part 2. //td[1] - locates first column of the table

    • Part 3. //text()[starts-with(normalize-space(), 'A')] - locates text which starts with letter A within the current node

    • Part 4. //following::td[3] -- locates 3rd column from the current node which is Current Prince (Rs)

    For your reference(see below):

    enter image description here