How to read the row number with having column data?

  • I'm automating an app and using winappdriver tool with java language for the same. I am selecting a row and click on that row in GUI. Here i am deleting a row , so I am having sequence number and with that sequence number I need to delete the row.

    This is the snap of UI Spy :

    enter image description here

    Here sequence number value is 5, but I want to click the row 3.

    //here loopng through each row by row..
    String seqNoData=alEvents.get(i).sequenceNumber; //data (sequcenceNumber) from db
    List<WebElement> pbp_insert = mainEntrySession.findElementByName("DataGridView").findElements(By.tagName("./*[contains(@LocalizedControlType, 'table')]"));                                     
                        List<WebElement> pbp_insert_grid_cells = pbp_insert.get(0).findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
              //    pbp_insert_grid_cells--contains all cellvalues  
                        for(int cellIndex = 14;cellIndex < pbp_insert_grid_cells.size();cellIndex=cellIndex+17) //14 th column is sequence number
                            rowSequenceNo = pbp_insert_grid_cells.get(cellIndex).getText(); //read sequence number from gui

    //sequcence number 5==5 mtching, how to get the sequcen number row 3 and row 3 parent //here how to fetch parent from child to click on that row.. }

  • There is no simple way to find the element's parent if you already have a child in WebElement when you use WinAppDriver. However you can use the work-around the idea of which I demonstrate in the below example:

    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");
        WindowsDriver driver = new WindowsDriver(new URL(""), capabilities);
        WebElement element = driver.findElementByAccessibilityId("num8Button");
        WebElement parentElement = findParent(element, driver);
    static WebElement findParent(WebElement child, WebDriver driver){
        String automationId = child.getAttribute("AutomationId");
        return driver.findElement(By.xpath("//*[./*[@AutomationId='" + automationId + "']]"));

    Code explanation:

    Basically, here you introduce helper method that takes your element, extracts AutomationId attribute value and builds xpath query starting from the top of the dom. That query is built in the way to find all the elements which have at least one child element having the given AutomationId. So if you have the structure like this:

    +-- el1
    |    |
    |    +-- el2 [AutomationId = 'blahblahId']
    +-- el3

    And if you pass el2 to that method, then it extracts value blahblahId and build the following xpath query: //*[./*[@AutomationId='blahblahId']]. This query will return element el1

Suggested Topics

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