C# 如何在Appium中启用和使用WebView实现iOS自动化
我正在尝试使用Ionic2/Angular2/Typescript开发的Appium自动化混合应用程序 当我试图识别元素时,我能够在Appium Inspector中的WebView中看到元素,但当我试图使用脚本识别它们时,它抛出了错误C# 如何在Appium中启用和使用WebView实现iOS自动化,c#,webview,automation,appium,appium-ios,C#,Webview,Automation,Appium,Appium Ios,我正在尝试使用Ionic2/Angular2/Typescript开发的Appium自动化混合应用程序 当我试图识别元素时,我能够在Appium Inspector中的WebView中看到元素,但当我试图使用脚本识别它们时,它抛出了错误 An element could not be identified using given search parameter. error: Invalid locator strategy: partial link text 我试图通过Xpath、na
An element could not be identified using given search parameter.
error: Invalid locator strategy: partial link text
我试图通过Xpath、name、linkText来识别elemnet,但我无法做到这一点
我还通过添加
capabilities.SetCapability("autoWebView", "true");
我用C#实现自动化。谁能提供解决方案
当我使用Xpath时,它显示了在处理命令时发生的未知服务器端错误(原始错误:connect ECONREFUSE)
当我调用var contextNames=driver.Contexts时,会显示上述错误代码>设置上述功能后。我还需要为浏览器设置功能吗?两件事:
1。确保在webview代码中将setWebContentsDebuggingEnabled
设置为true
2。在访问webview上的元素之前,请切换上下文并在操作后返回。类似于以下Java中切换到WEBVIEW的代码:
1)第一选项
下面的代码将有助于将本机应用程序处理到webview
public void acceptalert(){
Set<String> contextNames = idriver.getContextHandles();
System.out.println(contextNames);
for (String contextName : contextNames) {
if (contextName.contains("NATIVE_APP")) {
Reporter.log("Reaching to Native App", true);
idriver.context(contextName);
idriver.findElementByName("Open").click();
Reporter.log("Clicking Open to naviagte to Native APP", true);
}
else{
Reporter.log("Not found", true);
}
}
}
public void acceptablert(){
Set contextNames=idriver.getContextHandles();
System.out.println(contextNames);
for(字符串contextName:contextName){
if(contextName.contains(“本机应用程序”)){
Reporter.log(“访问本机应用程序”,true);
idriver.context(contextName);
idriver.findElementByName(“打开”)。单击();
日志(“单击Open to naviagte to Native APP”,true);
}
否则{
Reporter.log(“未找到”,true);
}
}
}
2)第二个选项:
try {
//idriver.context("WEBVIEW_2");
Set<String> contextNames1 = idriver.getContextHandles();
for (String winHandle : idriver.getWindowHandles())
{
if (winHandle.contains("WEBVIEW_24")){
((AppiumDriver) idriver).context(winHandle);
System.out.println("Switched to " + winHandle);
idriver.switchTo().window(winHandle);
idriver.findElementByName("Open").click();
}
else if (winHandle.contains("NATIVE_APP")) {
((AppiumDriver) idriver).context(winHandle);
idriver.switchTo().window(winHandle);
System.out.println("Switched to " + winHandle);
}
}
} catch (Exception e) {
}
试试看{
//idriver.context(“WEBVIEW_2”);
设置contextNames1=idriver.getContextHandles();
对于(字符串winHandle:idriver.getWindowHandles())
{
if(winHandle.contains(“WEBVIEW_24”)){
((AppiumDriver)idriver.context(winHandle);
System.out.println(“切换到”+winHandle);
idriver.switchTo()窗口(winHandle);
idriver.findElementByName(“打开”)。单击();
}
else if(winHandle.contains(“本机应用程序”)){
((AppiumDriver)idriver.context(winHandle);
idriver.switchTo()窗口(winHandle);
System.out.println(“切换到”+winHandle);
}
}
}捕获(例外e){
}
即使在使用
capabilities.SetCapability("autoWebView", "true");
我们需要访问代理来处理webview
Set<String> contextNames = idriver.getContextHandles();
System.out.println(contextNames);
for (String contextName : contextNames) {
if (contextName.contains("NATIVE_APP")) {
Reporter.log("Reaching to Native App", true);
idriver.context(contextName);
idriver.findElementByName("Open").click();
Reporter.log("Clicking Open to naviagte to Native APP", true);
}
else{
Reporter.log("Not found", true);
}
}
@@nullpointer我需要在哪里设置此“setWebContentsDebuggingEnabled”属性。我是否需要让我的开发人员在他们的代码中设置它,然后构建ipa/apk???@SurajGupta:是的,它设置在应用程序代码中。我在开发代码中检查了它,它已经设置为true。当我试图使用var contextNames=driver.contexts检索所有上下文时,您能解释一下为什么会出现以下错误吗代码>错误是在处理命令时发生的未知服务器端错误(原始错误:connect EconRefused)@SurajGupta:可能您需要更改代码,在回答中进行编辑。另外,当我浏览dot net客户端时,您可以直接使用以下内容设置上下文:driver=new AndroidDriver。。。driver.Context=“本机应用程序”代码>
capabilities.SetCapability("autoWebView", "true");
Set<String> contextNames = idriver.getContextHandles();
System.out.println(contextNames);
for (String contextName : contextNames) {
if (contextName.contains("NATIVE_APP")) {
Reporter.log("Reaching to Native App", true);
idriver.context(contextName);
idriver.findElementByName("Open").click();
Reporter.log("Clicking Open to naviagte to Native APP", true);
}
else{
Reporter.log("Not found", true);
}
}
ios_webkit_debug_proxy -c abad62540cbfc9f2af5c154985420a856e:27753 -d