如何参数化定位器?
我正在尝试存储属性文件中的定位器所需的所有值:
这是属性文件:
url=https://www.google.com
value=search
这是我的对象存储库类:
public class pageobjects extends helperclass{
public WebDriver driver;
By search = By.xpath("//input[@aria-label='search12()']") //I am trying to insert helpclass method here.
public class pageobjects(Webdriver driver){ //creating constructor
this.driver=driver; }
public WebElement search(){
return driver.findElement(search);
}
}
在这里,我不想在我的对象存储库文件中和在我的testcase文件,因此我尝试存储在属性文件中。我知道,通过使用“ load()”和“ getProperty()”,我可以阅读/加载属性文件。
这是我的助手类,包括从属性文件中存储特定字符串值的方法:
public helperclass {
public properties prop;
static String search12() {
prop=new Properties();
FileInputStream fis = new FileInputStream(path of property file);
return prop.getProperty("value");
}
}
error:string // input [@aria-label ='search12()']不是有效的xpath表达式。
I am trying store all values required for locators in Property File:
This is Property File:
url=https://www.google.com
value=search
This is my object repository class:
public class pageobjects extends helperclass{
public WebDriver driver;
By search = By.xpath("//input[@aria-label='search12()']") //I am trying to insert helpclass method here.
public class pageobjects(Webdriver driver){ //creating constructor
this.driver=driver; }
public WebElement search(){
return driver.findElement(search);
}
}
Here I don't want to hardcode "Search" in my object repository file and in my testcase file so I trying to store in a Property File. I know that by using "load ()" and "getProperty()", I can read/load Property File.
This is my helper class to consists of methods to store particular String value from Property file:
public helperclass {
public properties prop;
static String search12() {
prop=new Properties();
FileInputStream fis = new FileInputStream(path of property file);
return prop.getProperty("value");
}
}
Error: The String //input[@aria-label='search12()'] is not valid Xpath expression.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你为什么不尝试这个 -
Why don't you try this -