Automate iOS webkit within application
I am currently developing an ios app. One of the features in the app requires some WebKit automation. I am looking to do something similar to what selenium does; I want to input text into a textfield using its ID or Xpath and than press a button using its ID or Xpath.
Example: Inputting text into google search bar on google.com, and than clicking search programmatically.
I have done the above in selenium (Java). Although I am looking for a way to do this on ios (using swift). Is there anyway I can do this natively? Or is there a cocoapod I can use to do this? If not, would it be viable to use swift to run a javascript file to do this?
I am also aware of a cocoapod called WKZombie, it does exactly what I need it to although its documentation is fairly confusing and it is a headless browser (I want the user to see what is happening, so that doesn't work, although I could grab the HTML and display it if there is no other way to do this). Also I don't think appium will work because I want this to work in the standalone app.
(Also, this is my first post so I apologize for any improper improper formatting or anything like that)
ios swift selenium automation webkit
add a comment |
I am currently developing an ios app. One of the features in the app requires some WebKit automation. I am looking to do something similar to what selenium does; I want to input text into a textfield using its ID or Xpath and than press a button using its ID or Xpath.
Example: Inputting text into google search bar on google.com, and than clicking search programmatically.
I have done the above in selenium (Java). Although I am looking for a way to do this on ios (using swift). Is there anyway I can do this natively? Or is there a cocoapod I can use to do this? If not, would it be viable to use swift to run a javascript file to do this?
I am also aware of a cocoapod called WKZombie, it does exactly what I need it to although its documentation is fairly confusing and it is a headless browser (I want the user to see what is happening, so that doesn't work, although I could grab the HTML and display it if there is no other way to do this). Also I don't think appium will work because I want this to work in the standalone app.
(Also, this is my first post so I apologize for any improper improper formatting or anything like that)
ios swift selenium automation webkit
add a comment |
I am currently developing an ios app. One of the features in the app requires some WebKit automation. I am looking to do something similar to what selenium does; I want to input text into a textfield using its ID or Xpath and than press a button using its ID or Xpath.
Example: Inputting text into google search bar on google.com, and than clicking search programmatically.
I have done the above in selenium (Java). Although I am looking for a way to do this on ios (using swift). Is there anyway I can do this natively? Or is there a cocoapod I can use to do this? If not, would it be viable to use swift to run a javascript file to do this?
I am also aware of a cocoapod called WKZombie, it does exactly what I need it to although its documentation is fairly confusing and it is a headless browser (I want the user to see what is happening, so that doesn't work, although I could grab the HTML and display it if there is no other way to do this). Also I don't think appium will work because I want this to work in the standalone app.
(Also, this is my first post so I apologize for any improper improper formatting or anything like that)
ios swift selenium automation webkit
I am currently developing an ios app. One of the features in the app requires some WebKit automation. I am looking to do something similar to what selenium does; I want to input text into a textfield using its ID or Xpath and than press a button using its ID or Xpath.
Example: Inputting text into google search bar on google.com, and than clicking search programmatically.
I have done the above in selenium (Java). Although I am looking for a way to do this on ios (using swift). Is there anyway I can do this natively? Or is there a cocoapod I can use to do this? If not, would it be viable to use swift to run a javascript file to do this?
I am also aware of a cocoapod called WKZombie, it does exactly what I need it to although its documentation is fairly confusing and it is a headless browser (I want the user to see what is happening, so that doesn't work, although I could grab the HTML and display it if there is no other way to do this). Also I don't think appium will work because I want this to work in the standalone app.
(Also, this is my first post so I apologize for any improper improper formatting or anything like that)
ios swift selenium automation webkit
ios swift selenium automation webkit
asked Apr 6 '18 at 19:43
Swift GeekSwift Geek
357
357
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can communicate with the page loaded in a WKWebView
view via JavaScript:
The simplest way is to use
evaluateJavaScript(_, completionHandler)
which allows you to inject code, e.g. to change the DOM, trigger actions, etc.Or, you can inject a user script (
WKUserScript
) when creating the web view which can call back to your Swift code, which requires more setup but also is more powerful.
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
add a comment |
To host a browser in your application the class you need to use is WKWebView (replaces the older UIWebView). The evaluateJavaScript method can of WKWebView can be used to inject JS into the WKWebView instance. You can include the Textbox filling, button clicking magic into the JS that you are injecting.
add a comment |
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%2f49700017%2fautomate-ios-webkit-within-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can communicate with the page loaded in a WKWebView
view via JavaScript:
The simplest way is to use
evaluateJavaScript(_, completionHandler)
which allows you to inject code, e.g. to change the DOM, trigger actions, etc.Or, you can inject a user script (
WKUserScript
) when creating the web view which can call back to your Swift code, which requires more setup but also is more powerful.
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
add a comment |
You can communicate with the page loaded in a WKWebView
view via JavaScript:
The simplest way is to use
evaluateJavaScript(_, completionHandler)
which allows you to inject code, e.g. to change the DOM, trigger actions, etc.Or, you can inject a user script (
WKUserScript
) when creating the web view which can call back to your Swift code, which requires more setup but also is more powerful.
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
add a comment |
You can communicate with the page loaded in a WKWebView
view via JavaScript:
The simplest way is to use
evaluateJavaScript(_, completionHandler)
which allows you to inject code, e.g. to change the DOM, trigger actions, etc.Or, you can inject a user script (
WKUserScript
) when creating the web view which can call back to your Swift code, which requires more setup but also is more powerful.
You can communicate with the page loaded in a WKWebView
view via JavaScript:
The simplest way is to use
evaluateJavaScript(_, completionHandler)
which allows you to inject code, e.g. to change the DOM, trigger actions, etc.Or, you can inject a user script (
WKUserScript
) when creating the web view which can call back to your Swift code, which requires more setup but also is more powerful.
edited Nov 13 '18 at 10:35
answered Apr 6 '18 at 21:23
dr_bartodr_barto
2,56211130
2,56211130
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
add a comment |
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
Thank you very much. This is exactly what I was looking for!
– Swift Geek
Apr 6 '18 at 21:29
add a comment |
To host a browser in your application the class you need to use is WKWebView (replaces the older UIWebView). The evaluateJavaScript method can of WKWebView can be used to inject JS into the WKWebView instance. You can include the Textbox filling, button clicking magic into the JS that you are injecting.
add a comment |
To host a browser in your application the class you need to use is WKWebView (replaces the older UIWebView). The evaluateJavaScript method can of WKWebView can be used to inject JS into the WKWebView instance. You can include the Textbox filling, button clicking magic into the JS that you are injecting.
add a comment |
To host a browser in your application the class you need to use is WKWebView (replaces the older UIWebView). The evaluateJavaScript method can of WKWebView can be used to inject JS into the WKWebView instance. You can include the Textbox filling, button clicking magic into the JS that you are injecting.
To host a browser in your application the class you need to use is WKWebView (replaces the older UIWebView). The evaluateJavaScript method can of WKWebView can be used to inject JS into the WKWebView instance. You can include the Textbox filling, button clicking magic into the JS that you are injecting.
answered Apr 6 '18 at 21:22
PrajaktaPrajakta
17513
17513
add a comment |
add a comment |
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%2f49700017%2fautomate-ios-webkit-within-application%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