如何让元素@id 知道它在页面上显示的名称? 他在网站上的地址是:
//tr[@id='jqg223']/td[5]
代码地址:
td aria-describedby="blablabla" style="text-align: left;" role="gridcell" title="">G02</td>
他的名字/值(value)是例如G02
。
他需要从 jqg 中提取数字 (223) 到将递增 1 的变量
最佳答案
首先找到元素,然后调用getAttribute方法获取id。
例如:
如果你想要 td
元素 id:
driver.findElement(By.xpath("//td[contains(text(), 'G02')]")).getAttribute("id");
如果你想要 tr
元素 id:
driver.findElement(By.xpath("//td[contains(text(), 'G02')]/..")).getAttribute("id");
以G02
为变量:
driver.findElement(By.xpath("//td[contains(text(), '" + variableName + "')]")).getAttribute("id");
关于java - 如何从知道其值的单元格地址中捕获@id - Webdriver java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49513141/