1

I am trying to assert a certain Text element is present on a GUI I am testing. I can see the element using Inspect, yet when running my code, the element is not found. Interestingly, I cant use the "watch cursor" to select the element, I can only select it from the tree. Here is an image of the Inspect window displaying the element I am trying to assert is present: Inspect Image

I've tried asserting the Parent element is there so I know my XPath is okay. I've tried finding all children by appending /* to the path, and this seems to return null.

Heres the part of my test code I am trying:

string xpath_ABLRegion_child = "//*/Custom[@ClassName=\"D3NodeOverview\"]/Text[9]"]";

var WinElem_ABLRegion_child = desktopSession.FindElementByAbsoluteXPath(xpath_ABLRegion_child);

Assert.IsTrue(desktopSession.FindElementByAbsoluteXPath(xpath_ABLRegion_child"]").Displayed);

Console.WriteLine($"Text of WinElem_ABLRegion_child is {WinElem_ABLRegion_child.Text}");

I expect the test to pass, as WinElem_ABLRegion_child is displayed. However, I am getting an error that the element cant be found.

Please let me know if there is any more information I can share to help you help me.

dshimano
  • 11
  • 3

2 Answers2

0

You can try this....

fyi - your xpath will be extremely brittle. Can you cut that down a bit?

using C# - Method

        public static bool IsElementPresent_byXpath(string xpath)
    {
        bool result;
        try { result = Driver.FindElement(By.XPath(xpath)).Displayed; }
        catch (NoSuchElementException) { return false; }
        catch (StaleElementReferenceException) { return false; }
        return result;
    }

call

 bool ele = Browser.IsElementPresent_byXpath("your/long/xpath");
 Assert.IsTrue(ele);
Dazed
  • 1,527
  • 1
  • 13
  • 25
  • Thank you Dazed, I'll clean my XPath. This method, however, does not address my question. I want to know why WinAppDriver can't seem to find an element with I can see using the Inspect tool. – dshimano Jul 31 '19 at 19:42
  • Is it in an iFrame? – Dazed Aug 01 '19 at 00:12
  • It is not. I haven't run across any Iframes working with WinAppDriver. – dshimano Aug 01 '19 at 14:03
  • can you add the html markup that you are looking at? – Dazed Aug 01 '19 at 14:15
  • I'm not sure how to get the HTML using Microsoft Inspect, but I can add an image of the tree view I am looking for. – dshimano Aug 01 '19 at 14:40
  • yeah I am kind of at a loss as to why this would not display. Especially if you are getting the parent with no problem. The only thing I can think of is if you need to switch to it if it was an iframe or is there a chance there are two matching elements? – Dazed Aug 01 '19 at 14:48
  • I added the image. – dshimano Aug 01 '19 at 15:09
0

I noticed that the element you are looking for is the child of another window. Did you by chance assign the parent ownership? (I.e. owner = this on implementation). If so WinAppDriver seems to be blind to that bit of code. See ticket.

brandonwc5
  • 11
  • 1