Исключение в потоке «главная» org.openqa.selenium.Исключение StaleElementReferenceException: androidx.test.uiautomator.Исключение StaleObjectException

#java #selenium #selenium-webdriver #appium #appium-android

Вопрос:

Я пытался запустить это на Android-телевизоре, я вижу, что Appium может нажимать на все кнопки и вводить данные в текстовое поле, за исключением самого первого. я должен нажать на него, затем подождать и использовать ключи отправки, чтобы посмотреть, решит ли это проблему, но безуспешно. может ли кто-нибудь помочь мне в этом.введите описание изображения здесь

 Base.Java

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class Base {
    
    public static AndroidDriver<AndroidElement> capabalities() throws MalformedURLException {
        
        File file = new File ("src");
        File fs = new File(file,"TVTestApp_ct.apk");
        
        DesiredCapabilities capabalities = new DesiredCapabilities();
        capabalities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
        capabalities.setCapability(MobileCapabilityType.DEVICE_NAME, "Automation");
        capabalities.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath());
        AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),capabalities);
        return driver;
    }

}

HomeScreen.Java

import java.net.MalformedURLException;

import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.StaleElementReferenceException;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;

public class HomeScreen extends Base {
    
    public static void main(String[] args) throws MalformedURLException, InterruptedException {
        
        AndroidDriver<AndroidElement> driver = capabalities();
        
        driver.findElementById("com.tvexample.tvtestapp:id/editText").sendKeys("1234");
        driver.findElementById("com.tvexample.tvtestapp:id/editText1").sendKeys("1234")         
        
    }


}
 

Бревна:

 Jun 21, 2021 2:11:47 PM io.appium.java_client.remote.AppiumCommandExecutor$1 lambda$0
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: androidx.test.uiautomator.StaleObjectException
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'TXCDTL20CT1696', ip: '135.70.71.74', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '15.0.2'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: C:Userscg517nDocumentse..., appPackage: com.tvexample.tvtestapp, automationName: uiautomator2, databaseEnabled: false, desired: {app: C:Userscg517nDocumentse..., automationName: uiautomator2, deviceName: Automation, platformName: android}, deviceApiLevel: 28, deviceManufacturer: unknown, deviceModel: sdk_google_atv_x86, deviceName: emulator-5554, deviceScreenDensity: 320, deviceScreenSize: 1920x1080, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, pixelRatio: 2, platform: LINUX, platformName: Android, platformVersion: 9, statBarHeight: 0, takesScreenshot: true, viewportRect: {height: 1080, left: 0, top: 0, width: 1920}, warnings: {}, webStorageEnabled: false}
Session ID: 75f6f7db-21e8-407e-8a53-59271e4e9e02
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:247)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41)
    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.RemoteWebElement.execute(RemoteWebElement.java:285)
    at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
    at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
    at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:106)
    at HomeScreen.main(HomeScreen.java:18)
 

Комментарии:

1. Что такое строка 18 на главном экране?

2. это несколько предложений из Интернета, которые я пробовал, и я их прокомментировал. Для праздничности я их убрал.