iOS: Could not use button_click after upgrade appium_lib from 5.0.1 to 7.0.0

I was using Appium_lib 5.0.1 and able to use below method:
1: exists { button(buttonText)}
2: button(‘show alert’).click

But after appium_lib upgrade to version 7.0.0 I could not use the above methods.

Related to App: Nothing has been changed. If I switch back to previous version 5.0.1 then scripts are working as expected.

Can you please have a look into this.

Hey there
I won’t know for sure your exact problem, but I have had success with the above methods using Appium lib 7.0

If you can provide some logs and/or code snippets formatted (surrounded by 3 back tick marks) i’d be happy to take a look

code i am using:

wait_for_button_to_display button
    button("Sign In").click

from Appium inspector:
name: Sign In
type: UIAButton
value:
label: Sign In
enabled: true
visible: false
valid: true
location: {336, 916}
size: {96, 44}
xpath: //UIAApplication[1]/UIAWindow[1]/UIAButton[2]

Unfortunately, I could not see any required logs.

Ok, one thing jumps out but it’s speculation:

I couldn’t see any method in the repo here (https://github.com/appium/ruby_lib) that mentions wait_for_button_to_display, is that your method? In either case, is there a way to step into that method and see what exactly it’s trying to do?

I bet it’s related to the implicit wait change.

NOTE:
Personally, I really enjoy the explicit waits (the new way). I like having control over how long to wait for given elements to appear. There’s plenty of documentation here about how to use explicit waits. Feel free to respond more if you are stuck

Thanks!

I am using below code for implicit wait:
common.sky_wait_true { button_displayed? “Sign in” }

I tried using Sleep 20; Also
But still appium could not find the button.

Ok, Since I don’t know your app that well, Here’s what I would do:

  1. Try to get the appium ruby console (not the Appium Inspector) working on your environment. Head over to http://appium.io/slate/en/tutorial/ios.html?ruby#starting-the-console. You essentially start appium, then in another window start arc.

  2. Once you have arc running, you’ll see a prompt. type: page

  3. At this point, you should see all of your elements. One of them should be “Sign In”.

  4. You’ll have to figure out how “Sign In” is identified (by id, text, uiautomation, class, etc)

  5. Then, you’ll want to type something like this:

@yourElement={id:  "Sign In"}
wait = Selenium::WebDriver::Wait.new :timeout => 5
wait.until { find_element(@yourElement).click }

For @yourElement, i’m guessing there’s an accessibility id there. if there’s not, figure out how you can find that element.
The timeout of 5 is arbitrary. Put whatever number you think makes sense based on your app.

  1. If page found the Sign In element, i’m pretty sure the above will work. This works for me just fine in appium_lib 7.

NOTES (if the above doesn’t work)

  • It’s possible one of the appium_lib 7 dependent gems wasn’t installed. You can go back to the previous link on this thread about appium_lib 7 and check that out.
  • I haven’t used wait_true - but according to this (http://www.rubydoc.info/github/appium/ruby_lib/Appium/Common:wait_true) the documentation is relying on the old appium_lib 5’s implicit timeout of 30 seconds.

*That’s gone now in appium_lib 7. The default implicit wait in appium_lib 7 is 0 seconds. I’d recommend using the above example. I haven’t had problems with this at all.

Hope you find this helpful.
thanks!
Eric

Thank you very much.
everything now fine but just one doubt:
is button click method is there in 7.0.0?
like
name: Sign In
type: UIAButton
value:
label: Sign In
enabled: true
visible: false
valid: true
location: {336, 916}
size: {96, 44}
xpath: //UIAApplication[1]/UIAWindow[1]/UIAButton[2]

If I wanted to click Sign in (UIAButton) can I use button_click method? this is working in 5.0.1 but not in 7.0.0.
is it removed if yes is there any alternative to click a button.

So I looked in the ruby_lib for button_click. I did not see any references

If you take my previous example and you append a .click, you have what you need.
Specially
find_element(:id,“Sign In”).click

The advantage here is that you can use this on any clickable element - buttons or otherwise

Thank you guys:

now i am going to replace button_click and text_click with IDs.
earlier we dont have IDs in our developer’s code.