Unable to pass dynamic xpath in repository file?


  • QA Engineer

    My code is :

    for (int z = 0; z < rows.size(); z++) {
    
    rows.get(z).findElement(By.xpath("//*[@class='ng-scope'][" + (z + 1) + "]//*[@placeholder='Stop Name']")).sendKeys(shuttleObj.getStopArea());
    
    }
    

    And I want to use repository to pass xpath. I want this value multiple times for every rows in a table but if I am taking properties like

    for (int z = 0; z < rows.size(); z++) {
    
    rows.get(z).findElement(By.xpath(props.getProperty("path[" + (z + 1) + "]area")).sendKeys(shuttleObj.getStopArea()));
    
    }
    
    path=//*[@class='ng-scope']
    area=//*[@placeholder='Stop Name']
    

    This code is not working. If I am taking total elements like

    path=//*[@class='ng-scope'][" + (z + 1) + "]//*[@placeholder='Stop Name']
    

    It can be able to run but in same row. But I want this value in every rows in a table.



  • Hope this help you-
    Your property file-(db.properties)

    path=//*[@class='ng-scope'] 
    area=//*[@placeholder='Stop Name']  
    

    Now in your java class-

    String pathValue= props.getProperty("path");
    String areaValue= props.getProperty("area");
    
    for (int z = 0; z < rows.size(); z++) 
    {
    rows.get(z).findElement(By.xpath(pathValue+"[" + (z + 1) + "]"+areaValue)).sendKeys(shuttleObj.getStopArea());
    
    }  
    

    Note:- Here if your variable rows is also from properties file then with same above way use this.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2