Forum Discussion

Petewilson's avatar
Petewilson
Contributor
3 years ago

RegExp not selecting the FullName item I expected

I have a script, where i am trying to find and click a menu item, on a device in the BitBar cloud. Application is written in Flutter if any of that makes any difference.

 

I have a RegExp part of my script that needs to target the Menu item 'Cornice' and touch it. Unfortunately on this menu as the Menu title name is also Cornice this confused my script so i switched to looking at the FullName attribute.

 

The top Menu title FullName attribute is:

Mobile.Device("Apple iPad 10.2\" 9th A2602 15.2").Process("uk.co.rpssoftware.designer.anglian").FindElementByAccessibilityId("Cornice")

 

The Menu item, i want to touch, FullName attribute is:

Mobile.Device("Apple iPad 10.2\" 9th A2602 15.2").Process("uk.co.rpssoftware.designer.anglian").FindElementByAccessibilityId("Cornice\n")

 

So the difference is that the one i want to touch has '\n' at the end

 

 

This is my adjusted code to get my issue across

 

function RegExpDebug()
{
  var
  menuName,
  parentLevel,
  searchPattern,
  target;
  
  
  propertySearch = "FullName";
  menuName = "FindElementByAccessibilityId\(\"Cornice\\n\"\)";
  searchPattern = "regexp:" + menuName + "*";
  
  Log.Message("PropertySearch = " + propertySearch);
  Log.Message("MenuName = " + menuName);
  Log.Message("SearchPattern = " + searchPattern);
  
  parentLevel = Aliases.Device.process;
  Refresh_Appium_Content();
  target = parentLevel.Find(propertySearch, searchPattern, 20000);
  Log.Message("target = " + target.FullName);
  if (target.exists)
  {
    target.Touch();
  }
}

 

 

And this is the output from the logs. For some reason the target found and touched, is always the top menu option, rather than the menu item with FullName ending '\n'.

 

Can anyone offer any advice.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I suggest you read through Understanding Web Object Identification and Object Models

     

    Note, that FindElementByAccessibilityID method returns the first found object that matches the condition in the tree structure of Process("uk.co.rpssoftware.designer.anglian")

     

    You need to get the correct Parent for FindElementByAccessibilityID to work.

     

    Also, I think your coding is incorrect, as your Find method looks like this (if you remove all the other stuff),

    target = parentLevel.Find("FullName", "regexp:FindElementByAccessibilityId\(\"Cornice\\n\"\)*", 20000);

    Try something like this,

    target = parentLevel.Find("FullName", "Cornice\\n", 100);

     

     

     

     

    • Petewilson's avatar
      Petewilson
      Contributor

      I was attepting to do something like was in the RegExp help page (https://support.smartbear.com/testcomplete/docs/reference/misc/regular-expressions.html)

       

        // Get Notepad's main window by using a regular expressio

       

       

      window = notepad.Find("WndCaption", "regexp:.* Notepad", 5);

       

       

       

      so i didn't have to put the entire FullName for every menu option. I've used the Name attribute in the end

       

       

       

      target = parentLevel.Find("Name", "StaticText\(\"" + Cornice + "\\n\"\)", 100);

       

       

       

      which works but doesn't explain why the regexp, like below didn't work 

      target = parentLevel.Find("Name", "regexp:.*Cornice*", 100);
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The Notepad example that's shown,

    The Find method searches the property name WndCaption that matches the property value "* Notepad".

     

    In your example, the Find method searches the property name FullName that matches the property value "FindElementByAccessibilityId("Cornice\n")*"

     

    If you use the Object Spy tool on the UI Object "Cornice" does the property name FullName contain the property value e.g. "FindElementByAccessibilityId" ?

     

    • Petewilson's avatar
      Petewilson
      Contributor

      Sorry i didn't get notified that this had had a response so my apologies for to responding back sooner.

       

      FullName attribute was

       

      Mobile.Device("Apple iPad 10.2\" 9th A2602 15.2").Process("uk.co.rpssoftware.designer.anglian").FindElementByAccessibilityId("Cornice\n")

       

      Although i have since resolved the issue by using the Name field