【问题标题】:isDisplayed generic method for selenium硒的isDisplayed通用方法
【发布时间】:2016-05-04 23:00:29
【问题描述】:

我想为 selenium Web 驱动程序类创建一个通用方法 isDisplayed,它将接受 3 个参数 1) 驱动程序 2) locatorType 3) 定位器值 所以我想提出一个通用方法调用,它将解决 idnameclassnamexpath 的 isDislayed 方法强>。 请告诉我如何解决这个问题?

想法如果我在 java 中使用 switch 语句,我可以返回布尔值,例如 true 与否。但是开关无法达到其明显的回报

代码示例:http://chopapp.com/#5rrqt63f

【问题讨论】:

  • Laxmi 如果您向我们展示您已经尝试过的东西,而不是要求我们为您做,您将在这里获得更多帮助。

标签: java selenium-webdriver


【解决方案1】:

你可以尝试如下:

public boolean  method(WebDriver driver,  By locatortype){

        //do what u want
        boolean result = driver.findElement(locatortype).isDisplayed(); 
        return result;          
}

现在你可以像下面这样使用这个方法了:

By locatortype = By.cssSelector("selector");

By locatortype = By.id("id");

By locatortype = By.xpath("xpath");

并调用如下方法:

method(driver,locatortype);

【讨论】:

  • 如果你不想要布尔方法,而不是删除布尔值,使其无效并删除返回类型。
  • klaxmi361@gmail.com。让我知道你的身份证。将分享代码
猜你喜欢
  • 2018-02-15
  • 1970-01-01
  • 2020-05-30
  • 2018-12-02
  • 2013-08-06
  • 2022-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多