【问题标题】:Can we make a generic function which can take both mobile element and web element?我们可以制作一个可以同时包含移动元素和网络元素的通用函数吗?
【发布时间】:2018-12-14 17:10:34
【问题描述】:
public static < E > void clickOnElement( E element ) {

    }  

我正在尝试制作一个通用函数,当使用 selenium 时可以将元素类型作为 WebElement,而在使用 appium 时可以将元素类型作为 WebElement,这样我就可以执行点击事件。有人知道如何实施吗?

【问题讨论】:

    标签: selenium appium


    【解决方案1】:

    由于MobileElement实现了WebElement接口,您可以简单地将WebElement对象本身用于您的click()方法。

    考虑到你还是想做一个泛型方法,不用Generics就可以实现,直接用Objectclass:

    public static void clickOnElement(Object element ) {
    
    String className = element.getClass().getName();
    
    if(className.contains('WebElement'))
    {
     //do your WebElement stuff
    }
    
    else if(className.contains('MobileElement'))
    {
     //do your MobileElement stuff
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      • 2018-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-05
      相关资源
      最近更新 更多