Have created a POM with By locator concept and i need to select the value from the drop down list the code does not have the select option below is the code can some one pls tell me how to progress

+1 vote

In my utils have created the below code

public void selectvaluefromdropdown(By locator,String value)

{

List<WebElement> options = driver.findElements(locator);

for(int i=0;i<options.size();i++)

{

String option = options.get(i).getText();

System.out.println("Display all the options:"+ option);

if(option.equalsIgnoreCase(value))

{

options.get(i).click();

break;

}

}

}

}

//In the Page class have created the below code by calling the element utils class methods.cate is the one which need to select the value from the drop down

this is the locator for clicking the category drop down - By category = By.xpath("//div[@name='category']");

public void enterallfielddetails(String fname,String lname,String midname,String mail,String cate)

{

elementutils.waitforElementPresent(firstname);

elementutils.doSendKeys(firstname, fname);

elementutils.waitforElementPresent(lastname);

elementutils.doSendKeys(lastname, lname);

elementutils.waitforElementPresent(middlename);

elementutils.doSendKeys(middlename, midname);

elementutils.waitforElementPresent(email);

elementutils.doSendKeys(email, mail);

elementutils.selectvaluefromdropdown(category, cate);

In the Test Class has used the Data Provider to read the value from the Excel and called the DataProvider in the method :

Now when I run this getting a Data Provider mismatch is bz of the Category drop-down so how do I handle this

@DataProvider
public Object[][] getNewCompanydetails()
{
Object[][] data = ExcelUtil.getTestData(AppConstants.New_Company_Sheet_Name);
return data;
}
@Test(priority=3,dataProvider="getNewCompanydetails")
public void getCompanyDetails(String firstname,String lastname,String middlenames,String emailaddress,String category)
{
contactspage.enterallfielddetails(firstname, lastname, middlenames,emailaddress,category);
}
}
Aug 31, 2020 in Selenium by anonymous
• 180 points
1,379 views
Any error you are getting in the process? Could you please post it?
Yes Kim getting Data Provider Mismatch Error:

Below is the error:

org.testng.internal.reflect.MethodMatcherException:
Data provider mismatch
Method: getCompanyDetails([Parameter{index=0, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=1, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=2, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=3, type=java.lang.String, declaredAnnotations=[]}, Parameter{index=4, type=java.lang.String, declaredAnnotations=[]}])
Arguments: [(java.lang.String) chan,(java.lang.String) mike,(java.lang.String) re,(java.lang.String) add@add.com]

It is throwing MethodMatcherException because you are passing the same Data provider to different @Test Method, And Each test method has a different Parameter values. Parameters return by @DataProvider and @Test Method should match in order to retrieve and assign data.

You need to make sure what Data provider is returning, And you can assign it according to those Parameters to the Test method.

1)Yes i agree to what you say and iam aware as well but my question here is since iam using the  By locator i have created the below util to select the value from the drop down list:My question is with the given code how do i select the value from the drop down .Kindly refer the below code as the 1st one is the Utilities which i have created 

2)Second Code has the Page Class which has the method which calls the Utilities

3)Third Code contains the Test Class which has the Data Provider and the Test Method

1)Element Util Code

public void selectvaluefromdropdown(By locator,String value)

{

List<WebElement> options = driver.findElements(locator);

for(int i=0;i<options.size();i++)

{

String option = options.get(i).getText();

System.out.println("Display all the options:"+ option);

if(option.equalsIgnoreCase(value))

{

options.get(i).click();

break;

}
2)But in the Page : Method i need to call this method and have passed the holding parameter as String cate which has the xpath to click on the drop down list: below is the code:
2)Page Class Method Code
public void enterallfielddetails(String fname,String lname,String midname,String mail,String cate)
elementutils.selectvaluefromdropdown(category, cate);


}
3)Now in the Test Page i have created the Data Provider and the Category is read from the Excel which has the value as Contact  ..This Data Provider is given to the Test Method and the Test Method has the holding parameters.
3)Test Class Method Code
@DataProvider
public Object[][] getNewCompanydetails()
{
Object[][] data = ExcelUtil.getTestData(AppConstants.New_Company_Sheet_Name);
return data;
}
@Test(priority=3,dataProvider="getNewCompanydetails")
public void getCompanyDetails(String firstname,String lastname,String middlenames,String emailaddress,String category)
{
contactspage.enterallfielddetails(firstname, lastname, middlenames,emailaddress,category);
}
}
It might be bootstrap dropdown

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,747 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,178 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,253 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,890 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP