# Cant get any element after changing context to webview

**URL:** <https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437>\
**Category:** Support\
**Created:** [October 4, 2023, 6:20pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437 "2023-10-04T18:20:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 6:20pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/1 "2023-10-04T18:20:31Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 4, 2023, 7:19pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/2 "2023-10-04T19:19:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 7:31pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/3 "2023-10-04T19:31:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 4, 2023, 7:40pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/4 "2023-10-04T19:40:24Z")

</div>

then something wrong again.

try get full HTML tree with

```auto
               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:

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

```

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

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 8:33pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/5 "2023-10-04T20:33:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 8:41pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/6 "2023-10-04T20:41:32Z")

</div>

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

```auto
    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?

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 4, 2023, 9:02pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/7 "2023-10-04T21:02:40Z")

</div>

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](https://googlechromelabs.github.io/chrome-for-testing/#stable) from here 117 driver version for mac?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 9:04pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/8 "2023-10-04T21:04:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 4, 2023, 9:08pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/9 "2023-10-04T21:08:05Z")

</div>

You do not read red text in your link?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 4, 2023, 9:11pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/10 "2023-10-04T21:11:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 4, 2023, 9:23pm UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/11 "2023-10-04T21:23:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 7:30am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/12 "2023-10-05T07:30:56Z")

</div>

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

capabilities.setCapability(“chromedriverExecutable”, “/Users/nifargo/Downloads/chromedriver\_mac\_arm64/chromedriver”);

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 7:31am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/13 "2023-10-05T07:31:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 5, 2023, 7:59am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/14 "2023-10-05T07:59:06Z")

</div>

> [@Andrew\_Medvedev](#):
>
> and i cant understand

You have 2 chromes:

- one on your computer
- one on phone

On phone/emulator you have chrome 103. Correct?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 8:27am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/15 "2023-10-05T08:27:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 8:41am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/16 "2023-10-05T08:41:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 5, 2023, 8:53am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/17 "2023-10-05T08:53:09Z")

</div>

so update to 117 or fix appium auto download 🙂

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 9:08am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/18 "2023-10-05T09:08:52Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Andrew\_Medvedev](https://discuss.appium.io/user_avatar/discuss.appium.io/andrew_medvedev/32/11750_2.png) [@Andrew\_Medvedev](https://discuss.appium.io/u/Andrew_Medvedev)\
**Post date:** [October 5, 2023, 9:35am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/19 "2023-10-05T09:35:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [October 5, 2023, 10:04am UTC](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437/20 "2023-10-05T10:04:48Z")

</div>

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

mine commend tried in terminal

```auto
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/](https://appium.io/docs/en/2.1/guides/security/)  
`-allow-insecure=chromedriver_autodownload`

[Next page](https://discuss.appium.io/t/cant-get-any-element-after-changing-context-to-webview/40437.md?page=2)
