Cant get any element after changing context to webview

Im testing Android app with some webview pages

I use this method to find a context and change it to webview:

    Set<String> strcontext = null;
    try{
        strcontext = ((AndroidDriver) AppiumInit.getAppiumDriver()).getContextHandles();
        System.out.println("Found contexts size: '" + strcontext.size() + "'");
        for (String s :strcontext) {
            System.out.println("Found context: '" + s + "'");
            if (s.contains("WEBVIEW")) {
                System.out.println("Switching context to: '" + s + "'");
                ((AndroidDriver) AppiumInit.getAppiumDriver()).context(s);
                break;
            }
        }
    } catch (Exception e){
        e.printStackTrace();
    }

and i got it:
Found contexts size: ‘2’
Found context: ‘NATIVE_APP’
Found context: ‘WEBVIEW_com.dkveuroservice.mobileappkit.staging’
Switching context to: ‘WEBVIEW_com.dkveuroservice.mobileappkit.staging’

After that Im checking current context:
Current Context: WEBVIEW_com.dkveuroservice.mobileappkit.staging

Okay so with context everything is okay.

now I’m checking the text of the title:
public String getFeedbackWebTitl() {
WebDriverWait wait = new WebDriverWait(AppiumInit.getAppiumDriver(), Duration.ofSeconds(10));
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//span[@id=‘title’]")));

    WebElement feedbackWebTitle = ((AndroidDriver) AppiumInit.getAppiumDriver()).findElement(By.cssSelector("#title"));
    return feedbackWebTitle.getText();
}

but i got this error - org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //span[@id=‘title’] (tried for 10 second(s) with 500 milliseconds interval)
Here is a link to the page - https://my-preprod.dkv-mobility.com/next-gen/feedback/general

i need to getText - What are your experiences with the DKV app?

What wrong with my code?

Eeee you are in web context. Now imagine how you write test in pure web? Try use same find with css selector not xpath.

Btw how finally you succeeded switch to web?

i found out that after @beforeall i open the app one more time, and I have 2 apps in the same time.

i had cssSelector before xpath - it doesn’t work.

then something wrong again.

try get full HTML tree with

               try {
                    Document doc = Jsoup.parseBodyFragment(driver.findElement(By.cssSelector("body")).getAttribute("outerHTML"));
                    Logger.log("\n" + doc.toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }

or even simple:

System.out.println(driver.getPageSource())

also add what in appium server debug logs… it can help

yes you are right i can change the context but i have a problem with driver

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 117.0.5938.149 with binary path /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

how i can fix it?

now i get new chromedriver from the website
and add it to my caps:

    public void configureAndroidDriver() {
        // Android Local configuration
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "autoTests");
//        capabilities.setCapability(MobileCapabilityType.UDID, "1af75d19");
        capabilities.setCapability(MobileCapabilityType.APP, "//Users//nifargo//Documents//DkvProject//web-app-framework-qa-ui-tests//src//test//resources//androidReleaseBuild.apk");
        capabilities.setCapability("automationName", "UiAutomator2");
        capabilities.setCapability("appPackage", "com.dkveuroservice.mobileappkit");
        capabilities.setCapability("appActivity", "com.dkveuroservice.mobileappkit.MainActivity");
        **capabilities.setCapability("chromedriverExecutable", "/Users/nifargo/Downloads/chromedriver_mac_arm64/chromedriver");**
        capabilities.setCapability("showChromedriverLog", true);
        capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 500);
        String ipAddress = new Properties().getProperty("ipAddress");

after that I got this error:
io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: A new session could not be created. Details: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 103.0.5060.71 with package name com.dkveuroservice.mobileappkit

How is it possible?

Just to check.

  1. Strange that auto driver download does not work. You run appium server with this flag?
  2. You downloaded https://googlechromelabs.github.io/chrome-for-testing/#stable from here 117 driver version for mac?

1.yes.
2.emmm no i downloaded it from here - https://chromedriver.chromium.org/downloads
arm64 version cause I have mac with m1

You do not read red text in your link?

ooo im sorry i missed that…

but even with new 117 chrome driver version that I added to my caps I got this error:

io.appium.java_client.NoSuchContextException: An unknown server-side error occurred while processing the command. Original error: A new session could not be created. Details: session not created: This version of ChromeDriver only supports Chrome version 117
Current browser version is 103.0.5060.71 with package name com.dkveuroservice.mobileappkit

So this is now version of chrome inside your emulator. Update it to 117 also…

Or double check in logs why Appium not downloading automatically needed driver…

How can i do it?
i thought that i did it with my caps:

capabilities.setCapability(“chromedriverExecutable”, “/Users/nifargo/Downloads/chromedriver_mac_arm64/chromedriver”);

and i cant understand - if i change chromedriver version in my caps - my current version is changed as well but i dont understand how?

You have 2 chromes:

  • one on your computer
  • one on phone

On phone/emulator you have chrome 103. Correct?

can i check it with this command in android studia? adb shell getprop ro.build.version.release?

if yes - I got 13 as a response

but yes if i open chrome browser in emulator - I can see the version is 103

so update to 117 or fix appium auto download :slight_smile:

but as you can see i added a code for autodownload:

    server = new AppiumServiceBuilder()
            .withAppiumJS(new File("//usr//local//lib//node_modules//appium//build//lib//main.js"))
            .withIPAddress(ipAddress)
            .usingPort(Integer.parseInt(port))
            .withLogFile(new File("appium.log"))
            .withTimeout(Duration.ofSeconds(30))
            .withArgument(()->"--allow-insecure","chromedriver_autodownload")
            .build();
    server.start();

How can I for fix it more?

and yes in logs i found it - Automated Chromedriver download is disabled. Use ‘chromedriver_autodownload’ server feature to enable it

try add also --relaxed-security. check debug logs ARE all arguments applied while appium started?

mine commend tried in terminal

appium --log-level debug --port 6009 --keep-alive-timeout 1800 --session-override --log-timestamp --use-plugins execute-driver --relaxed-security --allow-insecure=chromedriver_autodownload
2023-10-05 10:07:01:676 - [Appium] Attempting to load plugin execute-driver...
2023-10-05 10:07:01:678 - [debug] [Appium] Requiring plugin at /Users/alekseimedvedjev/.appium/node_modules/@appium/execute-driver-plugin
2023-10-05 10:07:01:771 - [Appium] Welcome to Appium v2.0.0-beta.61
2023-10-05 10:07:01:773 - [Appium] Non-default server args:
2023-10-05 10:07:01:775 - [Appium] {
2023-10-05 10:07:01:775 - [Appium]   allowInsecure: [
2023-10-05 10:07:01:775 - [Appium]     'chromedriver_autodownload'
2023-10-05 10:07:01:775 - [Appium]   ],
2023-10-05 10:07:01:775 - [Appium]   keepAliveTimeout: 1800,
2023-10-05 10:07:01:776 - [Appium]   logTimestamp: true,
2023-10-05 10:07:01:776 - [Appium]   port: 6009,
2023-10-05 10:07:01:776 - [Appium]   relaxedSecurityEnabled: true,
2023-10-05 10:07:01:776 - [Appium]   sessionOverride: true,
2023-10-05 10:07:01:776 - [Appium]   usePlugins: [
2023-10-05 10:07:01:776 - [Appium]     'execute-driver'
2023-10-05 10:07:01:776 - [Appium]   ]
2023-10-05 10:07:01:777 - [Appium] }

i see in docs now “=” -> maybe need update to it? -> https://appium.io/docs/en/2.1/guides/security/
-allow-insecure=chromedriver_autodownload