Fetch UIBUtton without title XCUITest swift
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have an UIButton in my view, I want to tap on it in my XCUITest case.
This button doesn't have accessibility identifier or title. There is an image in the button.
I want to know how to access an UIButton which has no title or identifier in it.
app.buttons["title"].tap
would work for button with titles.
I have tried using recorder option form Xcode, but it's providing a very long path & i am looking for any alternative solution.
let element = app.children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 2).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
XCTAssert(element.children(matching: .button).element.exists, "Button not found")
element.children(matching: .button.element.tap()
NOTE:- I am not allowed to make any changes in the application code.
Thanks in advance for help.
ios swift testcase xcuitest uitest
|
show 1 more comment
I have an UIButton in my view, I want to tap on it in my XCUITest case.
This button doesn't have accessibility identifier or title. There is an image in the button.
I want to know how to access an UIButton which has no title or identifier in it.
app.buttons["title"].tap
would work for button with titles.
I have tried using recorder option form Xcode, but it's providing a very long path & i am looking for any alternative solution.
let element = app.children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 2).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
XCTAssert(element.children(matching: .button).element.exists, "Button not found")
element.children(matching: .button.element.tap()
NOTE:- I am not allowed to make any changes in the application code.
Thanks in advance for help.
ios swift testcase xcuitest uitest
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44
|
show 1 more comment
I have an UIButton in my view, I want to tap on it in my XCUITest case.
This button doesn't have accessibility identifier or title. There is an image in the button.
I want to know how to access an UIButton which has no title or identifier in it.
app.buttons["title"].tap
would work for button with titles.
I have tried using recorder option form Xcode, but it's providing a very long path & i am looking for any alternative solution.
let element = app.children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 2).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
XCTAssert(element.children(matching: .button).element.exists, "Button not found")
element.children(matching: .button.element.tap()
NOTE:- I am not allowed to make any changes in the application code.
Thanks in advance for help.
ios swift testcase xcuitest uitest
I have an UIButton in my view, I want to tap on it in my XCUITest case.
This button doesn't have accessibility identifier or title. There is an image in the button.
I want to know how to access an UIButton which has no title or identifier in it.
app.buttons["title"].tap
would work for button with titles.
I have tried using recorder option form Xcode, but it's providing a very long path & i am looking for any alternative solution.
let element = app.children(matching: .window).element(boundBy: 0).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 2).children(matching: .other).element.children(matching: .other).element.children(matching: .other).element.children(matching: .other).element(boundBy: 0)
XCTAssert(element.children(matching: .button).element.exists, "Button not found")
element.children(matching: .button.element.tap()
NOTE:- I am not allowed to make any changes in the application code.
Thanks in advance for help.
ios swift testcase xcuitest uitest
ios swift testcase xcuitest uitest
edited Nov 29 '18 at 4:18
Developer
asked Nov 29 '18 at 3:53
DeveloperDeveloper
520619
520619
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44
|
show 1 more comment
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531593%2ffetch-uibutton-without-title-xcuitest-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53531593%2ffetch-uibutton-without-title-xcuitest-swift%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I'd push back against the "I am not allowed to make any changes in the application code" requirement and give the button an accessibility identifier.
– Michael Reneer
Nov 29 '18 at 3:58
@MichaelReneer :- I have already asked the developer to add accessibility identifier & it's not feasible for them at this point of time, so i am looking for any other alternative option if available.
– Developer
Nov 29 '18 at 4:01
The other option is don't test the code until you can go back and add the accessibility identifier. You could try and use an NSPredicate and developer.apple.com/documentation/xctest/xcuielementquery/… or you could try drilling into the hierarchy with developer.apple.com/documentation/xctest/xcuielementquery/…, but it's going to be hard to read and end up being really fragile
– Michael Reneer
Nov 29 '18 at 4:30
@MichaelReneer Thanks for the quick response. I'll look into these alternatives.
– Developer
Nov 29 '18 at 4:43
Considering your limitations w.r.t adding the accessibility identifier .. and assuming your UI won't change quite often, you can do something like XCUIApplication().buttons.element(boundBy: ). Again, this is not an ideal solution but might work in your situation.
– Eric Blair
Nov 29 '18 at 4:44