使用android驱动程序未初始化Object映射。每当尝试使用任何sendkeys或点击时,该对象都会抛出null pointer exception
。
请在下面找到代码段: -
OR中使用的代码:
@FindAll({ @FindBy(xpath = "//*[@id='tsbb']") })
public WebElement Google_homepage__ssearchBTN;
WebDriver driver;
public tesitng_android_om(WebDriver driver){
this.driver=driver;
}
内部测试用例:
Android driver = new AndroidDriver(sURL, oCap);
tesitng_android_om tesitng_android_om = new tesitng_android_om((WebDriver)driver);
PageFactory.initElements((WebDriver)driver,tesitng_android_om);
tesitng_android_om.Google_homepage__ssearchBTN.click();
相同的代码适用于 Selenium 3.4.0 ,但无法在 3.8.1中运行
以下是问题的堆栈跟踪:
> Error: java.lang.NullPointerException at
> org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
> at
> org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:320)
> 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.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(LocatingElementHandler.java:51)
> at com.sun.proxy.$Proxy11.isDisplayed(Unknown Source) at
> org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:315)
> at
> org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:44)
> at
> org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:301)
> at
> org.openqa.selenium.support.ui.ExpectedConditions$10.apply(ExpectedConditions.java:298)
> at
> org.openqa.selenium.support.ui.ExpectedConditions$23.apply(ExpectedConditions.java:686)
> at
> org.openqa.selenium.support.ui.ExpectedConditions$23.apply(ExpectedConditions.java:682)
> at
> org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
> at myPackage.library.Android$Helper.checkReady(Android.java:2397) at
> myPackage.library.Android$Web.awType(Android.java:1108) at
> myPackage.testScripts.test_android_tcweb.test(test_android_tcweb.java:64)
> 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.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
> at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at
> org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at
> org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at
> org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
> at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
> at org.testng.TestRunner.privateRun(TestRunner.java:767) at
> org.testng.TestRunner.run(TestRunner.java:617) at
> org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at
> org.testng.SuiteRunner.access$000(SuiteRunner.java:37) at
> org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:368) at
> org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64) at
> java.util.concurrent.FutureTask.run(Unknown Source) at
> java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
> java.lang.Thread.run(Unknown Source)
> -- false -- [Expected - True, Actual - False]
答案 0 :(得分:0)
而不是以下代码块:
tesitng_android_om tesitng_android_om = new tesitng_android_om((WebDriver)driver);
PageFactory.initElements((WebDriver)driver,tesitng_android_om);
替换为:
tesitng_android_om tesitng_android_om_page = PageFactory.initElements(driver, tesitng_android_om.class);