I have 2 methods in one class. from first i contains strings and return index. In 2nd I try to use this index to find element. But I have error in eclipse "the method containsStatsName() in the type SettingsPage is not applicable for the arguments java" What i have to do to work correctly??
SettingPage.class
public int containsStatsName(String statusName){
int statListPos =0;
int statsNumber = getStatusList.size();
for(int i=0;i<statsNumber;i++){
if(getStatusList.get(i).getText().toLowerCase().contains(statusName)){
statListPos = i+1;
}
}
return statListPos;
}
public void editStatsName(){
int leadNewPos = containsStatsName();
int buttonNumber = getButtonList.size();
int couterNew = 0;
for(int i=0;i<buttonNumber;i++){
if(couterNew == leadNewPos){
getButtonList.get(i).click();
break;
}else{
couterNew++;
}
}
}
MainPage.class
SettingsPage sp = new SettingsPage(driver);
sp.gotoLeadStat();
sp.containsStatsName("new");
sp.editStatsName();
You can nest the method containsStatsName as parameter of the 2nd method...
sp.gotoLeadStat();
sp.editStatsName(sp.containsStatsName("new"));
and modify the editStatsName Method.
public void editStatsName(int leadPosition){
int leadNewPos = leadPosition;
int buttonNumber = getButtonList.size();
int couterNew = 0;
for(int i=0;i<buttonNumber;i++){
if(couterNew == leadNewPos){
getButtonList.get(i).click();
break;
}else{
couterNew++;
}
}
Your problem lies here:
public void editStatsName(){
int leadNewPos = containsStatsName();
Your containsStatsName method takes a String parameter, there is no method with that name defined that takes no parameter, so the compiler tells you there is a problem.
You can modify your editStatsName method by giving it the parameter statusName:
public void editStatsName(String statusName){
int leadNewPos = containsStatsName(statusName);
with that you give your containsStatsName method the parameter it needs.
But since the parameter that your editStatsName method really needs is the index and not the statusName - I would throw the containsStatsName method out of editStatsName , as you already call it in your main method:
public void editStatsName(int leadNewPos){
int buttonNumber = getButtonList.size();
int couterNew = 0;
for(int i=0;i<buttonNumber;i++){
if(couterNew == leadNewPos){
getButtonList.get(i).click();
break;
}else{
couterNew++;
}
}
and call both methods in your main method like that:
int statListPos = sp.containsStatsName("new");
sp.editStatsName(statListPos);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.