动态网站 https://demo.guru99.com/test/web-table-element.php – 如何查找Xpath

huangapple go评论106阅读模式
英文:

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

问题

在上述提供的链接中,如何找到XPath?
动态地获取以字母A开头的公司的当前价格,表格会动态变化。

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

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")]

答案1

得分: 1

以下XPath表达式是您需要的:

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

解释:此XPath表达式定位以字母'A'开头的'Company'的'Current Price'。

让我逐部分解释:

  1. 第一部分://table[@class='dataTable'] - 定位具有attribute=classvalue=dataTabletable元素。

  2. 第二部分://td[1] - 定位表格的第一列。

  3. 第三部分://text()[starts-with(normalize-space(), 'A')] - 定位在当前节点内以字母A开头的文本。

  4. 第四部分://following::td[3] - 定位从当前节点开始的第三列,即Current Prince (Rs)

供您参考(见下图):

动态网站 https://demo.guru99.com/test/web-table-element.php – 如何查找Xpath

英文:

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):

动态网站 https://demo.guru99.com/test/web-table-element.php – 如何查找Xpath

答案2

得分: 0

提取以字母A开头的公司的当前价格,您可以使用以下任何一种定位策略

  • XPATH和starts-with

    //table[@class='dataTable']//tbody//tr/td[./a[starts-with(normalize-space(), 'A')]]//following::td[3]
    
  • XPATH和following

    //table[@class='dataTable']//tbody//tr/td[./a[contains(., 'A')]]//following::td[3]
    
  • XPATH和following-sibling

    //table[@class='dataTable']//tbody//tr/td[./a[contains(., 'A')]]//following-sibling::td[3]
    
英文:

To extract the current price for company that starts with letter A you can use either of the following locator strategies:

  • XPATH and starts-with:

    //table[@class='dataTable']//tbody//tr/td[./a[starts-with(normalize-space(), 'A')]]//following::td[3]
    
  • XPATH and following:

    //table[@class='dataTable']//tbody//tr/td[./a[contains(., 'A')]]//following::td[3]
    
  • XPATH and following-sibling:

    //table[@class='dataTable']//tbody//tr/td[./a[contains(., 'A')]]//following-sibling::td[3]
    

huangapple
  • 本文由 发表于 2023年6月29日 23:02:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76582285.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定