如何从具有相同类值的两个表中选择一个表?

时间:2014-05-26 12:03:12

标签: java selenium selenium-webdriver

在UI上我看到两个表,每个表都有相同的类值,如何从这些表中选择一个表?

像:

<table class="content-grid" width="100%" cellspacing="0" cellpadding="0" summary="License Requirements by Type">
<table class="content-grid" width="100%" cellspacing="0" cellpadding="0" summary="Users and Unassigned devices">

如果我必须选择第一个表我该怎么做。我可以使用xpath吗?

WebElement table = driver.findElement(By.xpath("//table[@class='content-grid']"));

3 个答案:

答案 0 :(得分:0)

我认为它应该是//table[@summary='License Requirements by Type']//table[@summary='Users and Unassigned devices']

答案 1 :(得分:0)

您可以使用xpath,如下所示:

//table[@class='content-grid'][1]
//table[@class='content-grid'][2]

答案 2 :(得分:0)

Css选择器可帮助您选择如下。

WebElement table = driver.findElement(By.cssSelector("table[summary='License Requirements by Type']"))
相关问题