0

I'm automating an app and using winappdriver tool with java language for the same. I am selecting a row and clicking on that row in GUI. Here I am trying to delete a row. So I have a 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
                        
                        if(seqNoData==rowSequenceNo)
                        {

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

5
  • 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
    Commented Sep 11, 2018 at 5:34
  • Ho did you located sequence number value 5 in your code?
    – Alexey R.
    Commented Sep 11, 2018 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
    Commented Sep 11, 2018 at 11:10
  • I mean what is the code? How do you locate that element where you invoke getText() then?
    – Alexey R.
    Commented Sep 11, 2018 at 11:59
  • @AlexeyR. please check my code..how to get the parent element Row 3 from child sequence number row 3
    – user32519
    Commented Oct 2, 2018 at 9:15

1 Answer 1

0

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("http://127.0.0.1:4723"), capabilities);
    WebElement element = driver.findElementByAccessibilityId("num8Button");
    WebElement parentElement = findParent(element, driver);
    System.out.println(parentElement.getAttribute("Name"));
    driver.quit();
}

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:

root
|
+-- 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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.