Not able to select multiple value from drop down the code has Div tag and need to read the values from Excel using Data Provider

+1 vote

Element Utils which has the method:

Can some one please let me know what needs to be done in order to solve this issue

public void multiselectdropdown(By locator,String ...value)

{

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

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

{

String text = dropdownoptions.get(i).getText();

System.out.println(text);

try

{

if(!text.isEmpty())

{

if(text.equals(value))

{

dropdownoptions.get(i).click();

break;

}

}

}catch (Exception e)

{

}


}

}

}



Page which has the Method

public void pipeline(String fieldvalue,String savepipe)

{

elementutils.waitforElementPresent(DealsLink);

elementutils.doclick(DealsLink);

elementutils.waitforclickingElement(pipeline);

elementutils.doclick(pipeline);

elementutils.waitforElementPresent(Selectfieldsdropdownclick);

elementutils.doclick(Selectfieldsdropdownclick);

elementutils.multiselectdropdown(selectfieldsvalueselection, fieldvalue);


Test Page :

@DataProvider

public Object[][] dealpipeline()

{

Object data[][] = ExcelUtil.getTestData(AppConstants.Deal_Pipeline_Sheet_Name);

return data;

}

@Test(priority=10,dataProvider="dealpipeline")

public void getdealspipelineinfo(String selectfields,String savepipelineas)

{

dealspage.pipeline(selectfields, savepipelineas);

}

Excel :

selectfields 
Amount, Stage

(values are separated by comma)

Screenshot:

This is the drop-down which allows selecting 2 values at one time

Sep 15, 2020 in Selenium by sandhya
• 130 points
210 views
Could you please post the error that you are getting if any, after using the above code snippet?
i dont get any error it runs but does not select the value from the drop down list

So any solution for this

Hello @sandhya,

You can click on dropdown using this code :

   public static  void selectOption(WebDriver driver, String optionName) {
        List<WebElement> options = driver.findElements(By.xpath("//div[@class='selectize-dropdoun-content']//div[@class='option']"));
        options.forEach(option -> {
            if (option.getAttribute("innerText").equals(optionName)) {
                Actions actions = new Actions(driver);
                actions.moveToElement(option).click().build().perform();
            }
        });
    }

and then use like this:

String option = "Education";
selectOption(driver,option);
made changes to the code by using the split function but it is iterating from this block

for(int i=0;i<ar.length;i++)

{

for(int j=0;j<dropdownoptions.size();j++)

{

String text = dropdownoptions.get(i).getText();

System.out.println(text);

try

{

if(!text.isEmpty()) - to this block and is not going to click the webelement can any one suggest what needs to be done to get this issue resolved

Below is the full code

public void multiselectdropdown(By locator,String value)

{

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

String ar[] = value.split(",");

for(int i=0;i<ar.length;i++)

{

for(int j=0;j<dropdownoptions.size();j++)

{

String text = dropdownoptions.get(i).getText();

System.out.println(text);

try

{

if(!text.isEmpty())

{

if(text.equals(ar[i]))

{

System.out.println("Get the options:"+ar[i]);

dropdownoptions.get(j).click();

}

}

}catch(Exception e)

{

}

}
WebElement selectMyElement = driver.findElement(this.getObject(By.Id("Id of Your DropDown")));

selectMyElement.click();

Actions keyDown = new Actions(driver);

keyDown.sendKeys(Keys.chord(Keys.DOWN, Keys.DOWN)).perform();

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

+3 votes
1 answer

How to read excel file numeric data of all rows and column in selenium? I have 10 rows and 5 column but I read Only String value not a Numeric value?

Hey, @Mahendra, check this thread https://www.edureka.co/community/52170/read-numeric-data-from-excel-sheet-using-selenium-webdriver It deals with ...READ MORE

answered Jan 27, 2020 in Selenium by Sirajul
• 59,050 points
681 views
0 votes
0 answers
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,520 points
5,063 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,010 points
5,802 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,890 points
3,570 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 2, 2020 in Selenium by Sri
• 3,010 points
4,302 views