How is suposed to find those elements from FB

I’m trying to make a multiplatform login, so android and ios can make the same process. Until now I had an if to distinguish them. But don’t like at all.

finding the element by xpath is not an option, depending on ios version Cancel and OK buttons are swapped.
Finding by button_exact method isn’t also an option. It search by Value attribute and as you can see is empty
Finding by name is deprecated
finding by class is different from ios (UIAButton) than android (android.widget.Button)

What do you thing I should do? Finding by name here should work perfectly (or ids if facebook could add them…)

Thank you all

1 Like

What’s wrong with using the accessibility id locator? For iOS devices, this locator looks at the accessibility label. From the “label” field you have there, the OK button’s label is simply “OK”.

You could also use //*[@name='OK'] as an xpath expression.

Clicking it by id: “OK” Appium is clicking the cancel button, I don’t understand why… And if I try to click by id: “Cancel” it doesn’t find anything…
I’m going to take screenshots and logs

btw: I use ruby client, don’t know if the syntax you provided by searching through xpath but passing a name is available in ruby…

Now I see, clicking by id:“OK” it was clicking another button:

I will check if there are two okay buttons and if there are I will click the second one otherwise the first one. :smiley:
Thank you @afwang

(as you can see in first screenshot this button wasn’t there. Are AB Tests from Facebook TT)

i also use ruby and already clicked on that button in so many ways, but when i think i found the stable way to click it, for some reason, it stops working, here it is:

find_element(:xpath, '//*/*/*/UIAWebView[1]/UIAButton[2]').click
– but sometimes appium dont find the content of the webview

buttons('OK').last.click
– sometimes the app crashes when call it

truth is i still find the stable way to click it, sometimes it just goes crazy and don find it

To be clear, when I mention accessibility ID, I don’t mean to use the ID locator for finding your elements. Appium added a new locator strategy known as the accessibility ID locator a long time ago when they jumped to version 1.0 of the Appium server.

Accessibility ID searches the “label” field on iOS tests. The find_elements method has a small example about how to use it (although the example is listed in the Android documentation page, I believe it would also work for iOS tests, since the locator strategy is understood by the Appium server when used with the other languages).

I’m still with the same problem, it only detects one OK element. Only the browser’s one. Anything about the one I need.

find_elements(accessibility_id: "OK").size
=> 1

So:
1- Is a good notice to know about this identifier (which I assume that in android it searches by the same as id:)
2- Here there is a problem interacting with the elements from the webview

have you tried the commands that i suggested?

@juhlila thank you for your response, it’s little weird because I tried buttons_exact("OK") and never worked, but clicking by buttons('OK').last.click seems to work for now. The xpath approach isn’t an option since they change position between ios versions. Thank you

Hi you all again.

Now seems to stop working this approach.
Launching command wait(timeout: 35){buttons("OK").last.click} returns nil and doesn’t click anywhere.

Server Log for the entire wait (suposed to be 35 seconds)
[HTTP] --> POST /wd/hub/session/d86dfd52-e602-49c6-95fa-1e6bf3c9103e/execute {"script":"        (function() {\n        var opts = {\"typeArray\":[\"UIAButton\"],\"onlyVisible\":true,\"name\":{\"target\":\"OK\",\"substring\":true,\"insensitive\":true},\"label\":{\"target\":\"OK\",\"substring\":true,\"insensitive\":true},\"value\":{\"target\":\"OK\",\"substring\":true,\"insensitive\":true},\"onlyFirst\":false};\n        var result = false;\n\n        try {\n          result = $._elementOrElementsByType($.mainWindow(), opts);\n        } catch (e) {\n        }\n\n        return result;\n        })();\n","args":[]}
[MJSONWP] Calling AppiumDriver.execute() with args: ["        (function() {\n  ...
[debug] [iOS] Executing iOS command 'execute'
[debug] [UIAuto] Sending command to instruments:         (function() {
        var opts = {"typeArray":["UIAButton"],"onlyVisible":true,"name":{"target":"OK","substring":true,"insensitive":true},"label":{"target":"OK","substring":true,"insensitive":true},"value":{"target":"OK","substring":true,"insensitive":true},"onlyFirst":false};
        var result = false;

        try {
          result = $._elementOrElementsByType($.mainWindow(), opts);
        } catch (e) {
        }

        return result;
        })();

[debug] [Instruments] [INST] 2016-11-11 08:13:12 +0000 Debug: evaluation finished
[debug] [Instruments] [INST] 2016-11-11 08:13:12 +0000 Debug: responding with:
[debug] [Instruments] [INST] 2016-11-11 08:13:12 +0000 Debug: Running system command #87: /usr/local/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-uiauto/build/lib/bin/command-proxy-client.js /var/folders/q6/h757481s0331g8jz4t7tg1300000gp/T/instruments_sock 2,{"status":0,"value":""}...
[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: Got new command 87 from instruments:         (function() {
               var opts = {"typeArray":["UIAButton"],"onlyVisible":true,"name":{"target":"OK","substring":true,"insensitive":true},"label":{"target":"OK","substring":true,"insensitive":true},"value":{"target":"OK","substring":true,"insensitive":true},"onlyFirst":false};
        var result = false;
        try {
          result = $._elementOrElementsByType($.mainWindow(), opts);
        } catch (e) {
        }

        return result;
        })();


[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: evaluating         (function() {
               var opts = {"typeArray":["UIAButton"],"onlyVisible":true,"name":{"target":"OK","substring":true,"insensitive":true},"label":{"target":"OK","substring":true,"insensitive":true},"value":{"target":"OK","substring":true,"insensitive":true},"onlyFirst":false};
        var result = false;
        try {
          result = $._elementOrElementsByType($.mainWindow(), opts);
        } catch (e) {
        }

        return result;
        })();


[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: evaluation finished
[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: Lookup returned [object UIAButton] with the name "OK" (id: 9).
[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: Lookup returned [object UIAButton] with the name "URL" (id: 10).
[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: responding with:
[debug] [Instruments] [INST] 2016-11-11 08:14:16 +0000 Debug: Running system command #88: /usr/local/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-ios-driver/node_modules/appium-uiauto/build/lib/bin/command-proxy-client.js /var/folders/q6/h757481s0331g8jz4t7tg1300000gp/T/instruments_sock 2,{"status":0,"value":[{"ELEMENT":"9"},{"ELEMENT":"10"}]}...
[debug] [UIAuto] Socket data received (57 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":[{"ELEMENT":"9"},{"ELEMENT":"10"}]}
[MJSONWP] Responding to client with driver.execute() result: [{"ELEMENT":"9"},{"ELEMENT"...
[HTTP] <-- POST /wd/hub/session/d86dfd52-e602-49c6-95fa-1e6bf3c9103e/execute 200 839 ms - 106
[HTTP] --> POST /wd/hub/session/d86dfd52-e602-49c6-95fa-1e6bf3c9103e/element/10/click {"{}":""}
[MJSONWP] Calling AppiumDriver.click() with args: ["10","d86dfd52-e602-49c6-9...
[debug] [iOS] Executing iOS command 'click'
[debug] [UIAuto] Sending command to instruments: au.tapById('10')
[debug] [Instruments] [INST] 2016-11-11 08:14:17 +0000 Debug: Got new command 88 from instruments: au.tapById('10')
[debug] [Instruments] [INST] 2016-11-11 08:14:17 +0000 Debug: evaluating au.tapById('10')
[debug] [Instruments] [INST] 2016-11-11 08:14:17 +0000 Debug: target.frontMostApp().mainWindow().elements()[1].tap()
[debug] [UIAuto] Socket data received (25 bytes)
[debug] [UIAuto] Got result from instruments: {"status":0,"value":""}
[MJSONWP] Responding to client with driver.click() result: null
[HTTP] <-- POST /wd/hub/session/d86dfd52-e602-49c6-95fa-1e6bf3c9103e/element/10/click 200 1179 ms - 76

For me this seems to be a bug with appium, is only trying one time…
I know most of you don’t use the ruby client, but the syntax is good