Home > Enterprise >  is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming f
is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming f

Time:02-13

Is driver.getContextHandles() or driver.context() removed in Selenium4 as these methods are coming for Appium driver? I am Using Selenium 4.1.1 and JavaClient- 8.0.0-beta2.

Facing issue to find element while running a test in Hybrind app. Scenario A Web view is opening in App post click of an icon. Element not found exception is coming whereas element is uniquely found/identified in Chrome.

Any suggestions in this will help to procced further.

CodePudding user response:

Regarding the question about driver.context()

This moved to io.appium.java_client.remote.SupportsContextSwitching interface which also includes the default implementation.

In your tests if you're using AppiumDriver, just cast the driver, like:

io.appium.java_client.remote.SupportsContextSwitching

((SupportsContextSwitching) driver).getContextHandles();

NOTE: To have this work without ClassCastException, the driver initially should be created as AndroidDriver or IOSDriver, e.g.:

BaseOptions options = new UiAutomator2Options().setAutoGrantPermissions(true);
AppiumDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), options);

More Details

I mention this, because driver.context() is a special case of a larger context.

There are a lot of changes in appium java client version 8 from version 7.

One of them: A lot of platform-specific and not defined by W3C WebDriver standard methods moved out to additional interfaces.

So pure AppiumDriver doesn't have this methods.

But if we look throw the code, e.g. to AndroidDriver, we see it implements 20 additional interfaces:

public class AndroidDriver extends AppiumDriver implements
        PressesKey,
        SupportsRotation,
        SupportsContextSwitching,
        SupportsLocation,
        PerformsTouchActions,
        HidesKeyboard,
        HasDeviceTime,
        ...

and the same for IOSDriver.

If you cannot find some method in AppiumDriver, try to go throw the interfaces, which AndroidDriver/ IOSDriver are implementing.

  • Related