2016-11-19 96 views
0

我有應用程序,其中有一個動態Web表,我想選擇多個複選框中的一個列中的匹配值。動態Web表多個複選框選擇匹配列值

參見附件圖片:

Webapp snap

這是我到目前爲止已經試過:

List<WebElement> Rows = s.findElements((By.xpath("//a[text()='Nitesh Kumar']"))); 
System.out.println("No of rows = "+Rows.size()); 
int z=Rows.size(); 
int i =0; for(i=0;i<z;i++) 
{ 
    for (int j = 0; j < Rows.size(); j++) 
    { 
     s.findElement(By.xpath("//a[text()='Nitesh Kumar']/../../td[1]")).click(); 
    } 
} 
+0

'列表行= s.findElements((By.xpath( 「//一個[文本()= 'Nitesh庫馬爾']」))); (「No of rows =」+ Rows.size()); \t \t int z = Rows.size(); \t \t int i = 0; \t \t爲(I = 0; I Nik

回答

0

更改XPath來

//table[@id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')] 

找到從要素桌子。 一旦元素被發現獲取列表的大小和使用下面的XPath點擊複選框

//table[@id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1] 

完整的代碼會是這樣的下面。

List<WebElement> Rows = s.findElements((By.xpath("//table[@id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]"))); 
System.out.println("No of rows = "+Rows.size()); 
int z=Rows.size(); 
int i =0; 
for(i=0;i<z;i++) 
    { 
    for (int j = 0; j < Rows.size(); j++) 
    { 
     s.findElement(By.xpath("//table[@id='id of the table']/tbody/*/td[3]/a[text()='Nitesh Kumar')]../td[1]")).click(); 
    } 
    }