An element could not be located on the page using the given search parameters.

Appium自动化测试错误提示An element could not be located on the page using the given search parameters

最近在学习自动化测试由Python语言转向Java语言,前者测试同一APP可流畅运行,后者可启动APP,但一到相关定位时就没反应,Appium日志显示错误信息,Eclipse控制台报错,不知道是哪里出了问题希望得当帮助,谢谢各位!

错误截图

Eclipse错误截图: EclipEclipse控制台错误se控制台错误
APP启动界面截图:
默认启动APP页面
Appium日志截图:
Appium错误提示
项目结构截图:
在这里插入图片描述
测试代码截图:
在这里插入图片描述
在这里插入图片描述

代码

测试代码:

package qichezhijia;

import static org.junit.Assert.assertEquals;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.WebDriverWait;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;

public class QIche {
	 private AndroidDriver  driver;
	    private WebDriverWait wait;
	  
	   @Before
	  public void setup() throws Exception {
	        DesiredCapabilities cap = new DesiredCapabilities();
	        cap.setCapability("browserName", "");   //这里不需要设置浏览器,只有H5模式才设置为"chrome"或系统原始浏览器"browser" 
	        cap.setCapability("platformName", "Android"); //指定测试平台
	        //雷电安卓模拟器
	        cap.setCapability("deviceName", "emulator-5554"); //指定测试机的ID,通过adb命令`adb devices`获取
	        cap.setCapability("platformVersion", "5.1"); 
	        //安卓真机
	        //cap.setCapability("deviceName", "68U5T17A08002290"); //指定测试机的ID,通过adb命令`adb devices`获取
	        //cap.setCapability("platformVersion", "7.0"); 
	        
	        //将上面获取到的包名和Activity名设置为值
	        cap.setCapability("appPackage", "com.cubic.autohome");
	        cap.setCapability("appActivity", "com.cubic.autohome.LogoActivity");
	        
	        //A new session could not be created的解决方法
	        cap.setCapability("appWaitActivity","com.cubic.autohome.LogoActivity");
	        //每次启动时覆盖session,否则第二次后运行会报错不能新建session
	        cap.setCapability("sessionOverride", "true");
	        
	        //设置app每次运行不被重新初始化
	        cap.setCapability("noReset","true");
	        cap.setCapability("fullReset","false"); 
	        
	        //设置使用unicode键盘,支持输入中文和特殊字符
	        cap.setCapability("unicodeKeyboard", "true");
	        //设置用例执行完成后重置键盘
	        cap.setCapability("resetKeyboard", "true");
	        cap.setCapability("noSign", "true");
	        
	        //使用UiAutomator2框架便于获取toast信息
	        cap.setCapability("automationName", "UiAutomator2");
	        
	        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
	        wait = new WebDriverWait(driver, 15); 
	        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//隐式等待,最大超时10秒
	  }
	   
	  @Test
	  public void TestBig() throws InterruptedException{
		
		  driver.findElementByXPath("//android.widget.TextView[@text='下次再说']").click();
		  driver.findElementById("com.autohome.main.article:id/iv_search").click();
		  Thread.sleep(1000);
		  driver.findElementById("com.autohome.plugin.search:id/fragment_search_keyword_autocompleteview").sendKeys("大黄蜂");
	  
	      
	  }
	  
	   
	  @After
	  public void tearDown() throws Exception {
		  Thread.sleep(1000);   //暂停1秒
		  driver.quit();//关闭
	  }

}


控制台错误代码:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Cannot start the 'com.cubic.autohome' application. Original error: 'com.cubic.autohome.LogoActivity' or 'com.cubic.autohome.com.cubic.autohome.LogoActivity' never started (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.17 seconds
Build info: version: '3.6.0', revision: '6fbf3ec777', time: '2017-09-27T16:15:26.402Z'
System info: host: 'KIPKANG', ip: '192.168.100.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_251'
Driver info: driver.version: AndroidDriver
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
	at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
	at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
	at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
	at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$24(ProtocolHandshake.java:359)
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
	at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
	at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:362)
	at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:136)
	at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
	at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:89)
	at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:586)
	at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
	at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
	at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
	at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:217)
	at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:140)
	at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:83)
	at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
	at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:72)
	at qichezhijia.QIche.setup(QIche.java:55)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

java.lang.NullPointerException
	at qichezhijia.QIche.tearDown(QIche.java:80)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)


Appium日志代码:

Logcat] Stopping logcat capture
[ADB] Removing forwarded port socket connection: 8204 
[ADB] Running 'D:\android-sdk\platform-tools\adb.exe -P 5037 -s emulator-5554 forward --remove tcp\:8204'
[BaseDriver] Event 'newSessionStarted' logged at 1593943854948 (18:10:54 GMT+0800 (中国标准时间))
[MJSONWP] Encountered internal error running command: Error: Cannot start the 'com.cubic.autohome' application. Original error: 'com.cubic.autohome.LogoActivity' or 'com.cubic.autohome.com.cubic.autohome.LogoActivity' never started
[MJSONWP]     at ADB.callee$0$0$ (C:\Users\清濑灰二\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-utils.js:125:11)
[MJSONWP]     at tryCatch (C:\Users\清濑灰二\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[MJSONWP]     at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\清濑灰二\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
[MJSONWP]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\清濑灰二\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
[MJSONWP]     at GeneratorFunctionPrototype.invoke (C:\Users\清濑灰二\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[MJSONWP]     at 
[HTTP] <-- POST /wd/hub/session 500 61106 ms - 307
[HTTP] 

其他问题

使用的是老师给的APpiumDemo的java模板,在运行单机计算器时能正常运行,但换一下APP就出错了
-测试截图:
APP运行用例截图:
在这里插入图片描述
日志截图:
在这里插入图片描述
测试用例代码截图:
在这里插入图片描述
在这里插入图片描述

-照葫芦画瓢都能出错,实在是找不到哪里出了问题,孩子太难了,救救孩子吧。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值