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.. }

  • 1
    Can you clear out what is your issue. Heading says How to read the row number with having column data? and question says I am getting very slow to select. how to get row 3 click on very fast ?
    – NarendraR
    Sep 11 '18 at 5:34
  • Ho did you located sequence number value 5 in your code?
    – Alexey R.
    Sep 11 '18 at 10:14
  • @AlexeyR. Actually, in my gui screen , one sequence number column is there, so i am reading from there...just getText().. and convert it into integer
    – user32519
    Sep 11 '18 at 11:10
  • I mean what is the code? How do you locate that element where you invoke getText() then?
    – Alexey R.
    Sep 11 '18 at 11:59
  • @AlexeyR. please check my code..how to get the parent element Row 3 from child sequence number row 3
    – user32519
    Oct 2 '18 at 9:15

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

  • @Anthony see the explanation in update
    – Alexey R.
    Oct 1 '18 at 11:01
  • please check my question , i have edited
    – user32519
    Oct 1 '18 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy