I've got a webview that changes it's content when a button is pressed inside the webview. Is it possible to detect if webview has changed its content in XCUITest.
Edit: I would like a general way to know if the webview has updated without having to know the content the webview will update to–prior to the update.
Sure !
You can get your webview doing something like this:
let webview = app.webviews.firstMatch
Then, you can do some assertions on the webview content:
webview.staticTexts["TestString"].firstMatch.exists
Related
Need help on ios webview
I am trying to autofill a form located on any website can get path by ID or Xpath.
same with button want to know how to autotap send button after filling a form located on any website can get buttons xpath/ID
In selenium it was simple and easy dont know how to dive into webview looked everywhere
You use the javascript bridge to perform operations on elements using js. For example to tap on a button:
let jsString = "document.getElementById('myButtonID').click()"
myWebView.evaluateJavaScript(jsString, completionHandler: { result,error in
print(result);
})
When I am loading a URL in WebView for Android Lollipop 5.0, it shows a popup to choose a browser instead of showing the content in WebView itself. The same code was working fine in all earlier versions. What might be causing this?
Any help will appreciate.
this works for me
WebView webView = (WebView) findViewById(R.id.webLink);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl(url);
I have a problem in iOS 8 and UIWebView. I'm running an app into webview, in this app I have an icon to call the specific url. This is url that is registered like a application url (url scheme). Then into my UIWebView, when I press the button, other view controller should be shown.
In iOS 7 the button works fine, I tap on it and my other view controller is open. But in iOS 8 when I tap on the button nothing is happening. My method to handle url actions is never called.
The web page is using "window.location.href = MyUrlScheme://...", again this is working perfectly in iOS7, but not in iOS8.
Any ideas?
You've probably found the answer to this question, but I'll leave here my solution, it may help someone. I ran into this problem today, iOS8 UIWebView does not respond to window.location.href = "MyUrlScheme://do-something"...
So I added an Iframe to the html page, set the src attribute and removed the Iframe.
var sendObjectMessage = function(parameters) {
var iframe = document.createElement('iframe');
iframe.setAttribute('src', "MyUrlScheme://"+parameters);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
sendObjectMessage("send-something");
Take a look at this link https://gist.github.com/irace/3688560
I'm currently developing some UIAutomation tests for an iOS App using KIF Framework. At some point, the app has to open a WebView with a login page, enter username and password and then press the sign-in button and all of these have to be automated.
My question is: knowing that at a certain moment in time the app displays that login page, how can i get the WebView UI element as in:
UIWebView *webView = // . . . ?
Also, it would be great if you could tell me how to get those two text fields (username and password), something like:
UITextField *textField = // ... ?
Thank you.
Use this code :
NSString *myText = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.textContent"];
OR For all data
NSString *html = [webView stringByEvaluatingJavaScriptFromString:#"document.documentElement.outerHTML"];
OR Check this link
I Hope this code useful for you.
the idea is that you want to kif to get hold of the webview after the webview has been loaded..
for that you will have to put the notifiying code in the webview delegate function webViewDidFinishLoad
in there.. you can put an NSNotification.. if you've used KIF for a while you know that you can instantiate actions only after you have recieved an NSNotification.. this is the the method in kif:
+ (id)stepToWaitForNotificationName:(NSString*)name object:(id)object;
as for finding the UIWebView itself, you just have to give it the same accessibility label you do with any other UIElement in iOS.
I'm using webViewDidFinishLoad a lot in my app and there's something about UIWebView that really bugs me, well, actually two things.
The first, when I load new content to a UIWebView I will see for half a second the last page that was loaded to the same UIWebView what will force me to "clean" the UIWebView using something like:
[_mainWebView stringByEvaluatingJavaScriptFromString:#"document.open();document.close();"];
before loading the new content.
The second issue I have and that's the main issue for this question is that if i'll load some new content to my UIWebView and do something like this:
[_mainWebView loadHTMLString:htmlString baseURL:nil];
...
- (void)webViewDidFinishLoad:(UIWebView *)webView {
_mainWebView.alpha = 1;
}
In some cases the UIWebView will show up white for half a second before showing up the content. I'm guessing that the content is already loaded into the UIWebView and that's why webViewDidFinishLoad:webView is firing but for small html pages showing to content takes loner than the actual load. Is there any workaround I can use to avoid the blank screen that is showing for a sec or so but still save that second?
I thought about animating the alpha from 0 to 1 but that solution feels kinda lame to me.
Try adding a javascript callback so you know when the web view contents have actually loaded: Javascript in UIWebView callback to C/Objective-C