Ref*_*lux 2 selenium xpath selenium-rc
在Selenium RC中有没有办法从xpath获取id?
如果我有xpath
/html/body/div/div//input
Run Code Online (Sandbox Code Playgroud)
我想获取与xpath关联的所有节点的id
你可以getAttribute
结合使用getXpathCount
.
Java中的Selenium 1示例如下:
int inputs = selenium.getXpathCount("/html/body/div/div/descendant::input").intValue();
for (int i=1; i<=inputs; i++) {
System.out.println(selenium.getAttribute("/html/body/div/div/descendant::input[" + i + "]@id"));
}
Run Code Online (Sandbox Code Playgroud)
Java中的Selenium 2示例将是:
List<WebElement> inputs = driver.findElements(By.xpath("/html/body/div/div/descendant::input"));
for (WebElement input : inputs) {
System.out.println(input.getAttribute("id"));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
9494 次 |
最近记录: |