【发布时间】:2021-07-02 12:00:32
【问题描述】:
我有一个带有黄瓜和页面对象模式的 selenium 项目。我想用我在特征文件中给出的字符串参数调用java中的定位器对象。
例如
public class Locators{
public By btnLogout = By.cssSelector("a[href*='oidcLogout']"); #this is my locator
public By btnLogin = By.cssSelector("a[href*='login']");
}
When user click "btnLogout"
When user click "btnLogin" #this is my step in feature
我不想要这样的重复步骤。
When user click logout
When user click login
所以我想在我的动作类中做这样的动作
public void click(String elementLocators) {
Locators locators = new Locators();
driver.findElement(locators.elementLocators)
}
我怎样才能得到这样的定位器,或者你有什么想法吗?你能帮助我吗? 谢谢
【问题讨论】:
-
既然你已经创建了
Locators()的对象,你可以通过locators.btnLogout来获取By -
@cruisepandey 是的,但我想使用
click()方法作为按钮,如果我像locators.btnLogout一样使用它进行登录,我必须创建新方法。我不想要它。