2016-07-15 3 views
0

페이지의 요소를 확인하려고합니다. 테이블이 있고 여러 개의 입력이있는 행이 많이 있습니다. 테이블 행에서 입력에 액세스하는 방법? 대신 ID의 XPath를 사용하여 특정 입력 요소를 찾는 시도 할 수 있습니다 :Selenium Web Driver에서 테이블의 요소를 가져 오는 방법 JA

This is my java class 

public class Setting extends Page { 

    /**Identify Elements of the page*/ 

    @FindBy(id="table-settings") 

    private WebElement Table; 

    //Constructor 
    public Setting() 
    { 
     /**Initialize PageFactory WebElements*/ 
     PageFactory.initElements(driver, this); 
    } 

} 

답변

0

당신이 그것을

@Test 
public void test() { 
    WebElement Webtable=driver.findElement(By.id("TableID")); // Replace TableID with Actual Table ID or Xpath 

    List<WebElement> TotalRowCount=Webtable.findElements(By.xpath("//*[@id='TableID']/tbody/tr")); 

    System.out.println("No. of Rows in the WebTable: "+TotalRowCount.size()); 
    // Now we will Iterate the Table and print the Values 

    int RowIndex=1; 

    for(WebElement rowElement:TotalRowCount) 
    { 
     List<WebElement> TotalColumnCount=rowElement.findElements(By.xpath("td")); 
     int ColumnIndex=1; 

     for(WebElement colElement:TotalColumnCount) 
     { 
      System.out.println("Row "+RowIndex+" Column "+ColumnIndex+" Data "+colElement.getText()); 
      ColumnIndex=ColumnIndex+1; 
     } 
     RowIndex=RowIndex+1; 
    } 
} 
+0

작동하는 경우 질문의 평가를 높일 수 있습니다. –

0

이 시도에있는 장애물을 발견하면 알려주세요, 그에 따라 변경, 코드 아래 참조 . id가 특정 요소에 사용 가능한 경우 id 자체를 사용할 수 있습니다. 또한 당신의 생성자에서,

public Setting(WebDriver driver) 
{ 
    this.driver = driver; 
    /**Initialize PageFactory WebElements*/ 
    PageFactory.initElements(driver, this); 
} 

로하고 @FindBy 문 앞에

WebDriver driver; 

를 추가 수업 시도에

public Setting() 
{ 
    /**Initialize PageFactory WebElements*/ 
    PageFactory.initElements(driver, this); 
} 

에서 코드를 변경하려고합니다.