0

I am using the inspect tool and WinAppDriver and can't find an element among other elements inside application. The only different between all elements is the coordinates upon screen (this is the only different between each button). Can I find the element by the name (FindElementByName) that exists in the X place for example? or other idea?

Tnx

2 Answers2

0

You could have look at driver.PageSource to check if the elements maybe have some other attribute that distinguishes them that might not be visible via Inspect. If so, you could then use driver.FindElementByXPath to find the correct element, e.g.

driver.FindElementByXPath("//button[@attributeOne='valueOne'][@attributeTwo='valueTwo']")

Otherwise, as you mentioned you know there is a difference in position, you could also use xPath to query for the e.g. leftmost button:

driver.FindElementByXPath("//button[@x=min(//button[@name='theName']/@x)]")
rogi1609
  • 438
  • 3
  • 8
0

If the buttons are always at the same index, you can just loop through them all and find by index. Or better than looping, use FindElementsBy (notice Elements is plural).

I do this for several boxes who have the same name/accessibilityID:

public WindowsElement doStuff(WindowsDriver<WindowsElement> appSession, int index)
    {
        Elements = appSession.FindElementsByAccessibilityId("SpinnerTextBoxContent");

        return Elements[index];
    }

Then a simple call to

doStuff(appSession, 0);

Gets me what I need.

brandonwc5
  • 11
  • 1