You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Chrome下载中用Xpath获取父元素下role值及progress的value属性?

Chrome Downloads Page XPath Solutions

Got it, let's break down these two XPath problems for the Chrome Downloads page clearly:

1. Fetching the role attribute value from a child element under a parent element

To get the role attribute value of a child element nested under a specific parent, follow this approach:

  1. First target the parent element using its unique identifiers (like class, id, or other distinct attributes).
  2. Then narrow down to its child element that has a role attribute, and extract the attribute's value.

Example XPath:

Suppose your parent element is a download item container with class="download-item", here's how you'd grab the role value of its child:

//div[@class='download-item']/*[@role]/@role
  • If you know the exact tag name of the child element (e.g., span or button), you can make it more precise:
//div[@class='download-item']/span[@role]/@role
  • If you just want to locate the child element (not extract the role value), remove the trailing /@role:
//div[@class='download-item']/span[@role]

2. Getting the value attribute of an element with role="progress"

For the role="progress" element (which tracks download progress in Chrome's Downloads page), the XPath needs to first target this element, then extract its value attribute.

Basic XPath:

This works if there's only one progress element on the page, or you want to fetch all progress values:

//*[@role='progress']/@value

More precise XPath (with context):

If you need to target the progress element for a specific download (e.g., under a download item with a specific filename), chain the parent context to avoid ambiguity:

//div[contains(@aria-label, 'Your Download Filename')]/*[@role='progress']/@value
  • The value attribute here typically holds a numeric value representing the download completion percentage (ranging from 0 to 100).

内容的提问来源于stack exchange,提问作者springcloudlearner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:50:20