如何启用和使用Appium的WebView于iOS自动化 [英] How to enable and use WebView for iOS Automation in Appium
问题描述
我试图自动利用Ionic2 / Angular2 /打字稿开发Appium的混合应用程序。
I am trying to automate hybrid app using Appium developed by Ionic2/Angular2/Typescript.
当我试图找出元素,我能看到元素的WebView在Appium督察但是当我尝试使用脚本它抛出错误识别它们。
When I am trying to identify element I am able to see element in WebView in Appium Inspector but when I try to identify them using script it is throwing error.
An element could not be identified using given search parameter.
error: Invalid locator strategy: partial link text
我想通过Xpath的,姓名,LINKTEXT识别elemnet,但我不能这样做。
I am trying to identify elemnet through Xpath, name, linkText but I am not able to do so.
我也加入启用功能的WebView
I also enable webview in capabilities by adding
capabilities.SetCapability("autoWebView", "true");
我使用C#自动化。有谁能够提供解决方案?
I am using C# for automating. Can anybody provide the solution?
当我使用XPath它表明在处理命令(原来的错误:连接ECONNREFUSED),未知的服务器端错误发生
When I use Xpath it shows An unknown server side error occured while processing the command (Original error: connect ECONNREFUSED)
上面的错误,当我打电话时显示 VAR contextNames = driver.Contexts;
设定了上述功能之后。难道我还需要设置能力的浏览器???
Above error is displayed when I call var contextNames= driver.Contexts;
after setting the above capability. Do I also need to set capability for browser???
推荐答案
两件事情:
1 即可。确保 setWebContentsDebuggingEnabled
设置为true,在你的WebView code。
1. Ensure setWebContentsDebuggingEnabled
is set to true in your webview code.
2 。访问一个网页视图中的元素之前,操作后切换上下文和背部。类似于Java下面code东西切换到的的WebView 的:
2. Before accessing the elements on a webview, switch the context and back after the operations. Something similar to the below code in Java for switching to WEBVIEW :
Set<String> contextNames = driver.getContextHandles();
String setContext = contextNames.toArray()[1].toString();
driver.context(setContext);// set context to WEBVIEW_com.my.package
请不要阅读<一以下href=\"https://discuss.appium.io/t/what-does-the-autowebview-desired-capability-really-do/69/2?u=namannigam14\"相对=nofollow>究竟做autoWebview呢?
有关点网的客户端,类似code云为:
For dot-net client, a similar code goes as :
var contextNames = driver.GetContexts(); //correction to your code
driver.SetContext(contextNames[1]); // for webview_1, for native_view 0
这篇关于如何启用和使用Appium的WebView于iOS自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!