Selenium4 中是否删除了 driver.getContextHandles() 或 driver.context() ,因为这些方法将用于 Appium 驱动程序?

mit*_*lri 0 automation android-webview selenium-webdriver hybrid-mobile-app appium

Selenium4 中是否删除了 driver.getContextHandles() 或 driver.context() ,因为这些方法将用于 Appium 驱动程序?我正在使用 Selenium 4.1.1 和 JavaClient-8.0.0-beta2。

在混合应用程序中运行测试时遇到查找元素的问题。场景 单击图标后,Web 视图将在应用程序中打开。元素未找到异常即将到来,而元素在 Chrome 中是唯一找到/标识的。

任何建议都将有助于进一步进行。

Max*_*nka 5

关于以下问题driver.context()

这已转移到io.appium.java_client.remote.SupportsContextSwitching还包括默认实现的接口。

在您的测试中,如果您使用的是AppiumDriver,只需强制转换驱动程序,例如:

io.appium.java_client.remote.SupportsContextSwitching

((SupportsContextSwitching) driver).getContextHandles();
Run Code Online (Sandbox Code Playgroud)

注意:要在没有 的情况下进行此工作ClassCastException,驱动程序最初应创建为AndroidDriverIOSDriver,例如:

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

更多细节

我提到这一点,是因为driver.context()这是更大背景下的一个特例。

appium java客户端8版本相对7版本有很多变化。

其中之一:许多特定于平台且未由 W3C WebDriver 标准方法定义的方法移至其他接口。

所以pureAppiumDriver没有这个方法。

但如果我们仔细查看代码,例如 to AndroidDriver,我们会发现它实现了 20 多个附加接口:

public class AndroidDriver extends AppiumDriver implements
        PressesKey,
        SupportsRotation,
        SupportsContextSwitching,
        SupportsLocation,
        PerformsTouchActions,
        HidesKeyboard,
        HasDeviceTime,
        ...
Run Code Online (Sandbox Code Playgroud)

对于 也一样IOSDriver

如果您在 中找不到某些方法AppiumDriver,请尝试遍历AndroidDriver/IOSDriver正在实现的接口。