英文:
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'。
让我逐部分解释:
-
第一部分:
//table[@class='dataTable']
- 定位具有attribute=class
和value=dataTable
的table
元素。 -
第二部分:
//td[1]
- 定位表格的第一列。 -
第三部分:
//text()[starts-with(normalize-space(), 'A')]
- 定位在当前节点内以字母A开头的文本。 -
第四部分:
//following::td[3]
- 定位从当前节点开始的第三列,即Current Prince (Rs)
。
供您参考(见下图):
英文:
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 thetable
element withattribute=class
andvalue=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 isCurrent Prince (Rs)
For your reference(see below):
答案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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论