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

如何在C#中使用Selenium根据已知aria-label获取元素的aria-colindex值

实现代码

你已经完成了元素定位逻辑,直接调用Selenium IWebElement 内置的 GetAttribute() 方法即可获取目标属性值,最简实现只有一行:

// 获取字符串类型的aria-colindex值
string colIndexStr = driver.FindElement(By.XPath("//td[@aria-label='Sütun Stok']")).GetAttribute("aria-colindex");

如果需要得到整型的列索引,可以直接做类型转换:

int colIndex = int.Parse(driver.FindElement(By.XPath("//td[@aria-label='Sütun Stok']")).GetAttribute("aria-colindex"));

说明

GetAttribute() 方法支持读取元素的所有标准属性、自定义属性,包括 aria- 开头的无障碍属性,无需额外扩展逻辑。

目标元素参考截图

目标元素位置


内容的提问来源于stack exchange,提问作者Gülsen Keskin

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 07:24:05