0

Below is the XPath-

//XCUIElementTypeButton[@name="8/13"]

The numeric value in the above XPath changes and is not static. There are more then 10 buttons on the screen, I want to click on the first one.

Text1                 btn1   //let’s say btn1 contains 8/13

Text2                 btn2   //let’s say btn1 contains 4/8

Can anyone help me to achieve this task?

3
  • What other attributes can you access? Do any of these not change? You would need to change your XPath to use the different search criteria, but other than that it should be fairly straightforward.
    – Kate Paulk
    Commented Oct 22, 2018 at 19:39
  • @kate I do have id other than this XPATH which is also dynamically changing with number like 8/3, 4/8. And I need to select the first occurrence. Commented Oct 23, 2018 at 10:46
  • If you need the first occurrence of a button, //XCUIElementTypeButton[1] should do it. (Disclaimer: I am not an Xpath expert)
    – Kate Paulk
    Commented Oct 23, 2018 at 11:22

2 Answers 2

0

I think in XPath you are using the name or value which may be dynamic (keeps on changing). So, you can go for the concept of following sibling for getting the proper XPath.

Example:

 //XCUIElementTypeButton[@name='testing']/../following-sibling::XCUIElementTypeStaticText
0

If you are specifically mentioning as you want to click on the first button no matter the text, then I would go with List concept

@FindBy(xpath = "//XCUIElementTypeButton")
    private List<MobileElement> button;

button.get(0).click();

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.