What I am trying to do is select multiple options from this example site while holding CTRL
http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html
The multiple selection values would come from excel though, means if the excel rows has values as mushroom, onions and olives each on different rows (within same column) it will select only those values one by one within the page. The Excel file looks like this :
And this is the code I got so far upto
package mineP;
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Various {
public static void main(String[] args) throws Exception{
File src = new File("C:\\Users\\Documents\\myP2.xlsx");
// Load file
FileInputStream fis = new FileInputStream(src);
// Load WB
XSSFWorkbook wb = new XSSFWorkbook(fis);
// Load Sheet
XSSFSheet sh1 = wb.getSheetAt(0);
String chromePath = "C:\\Users\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromePath);
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html");
WebElement sel = driver.findElement(By.xpath("//select[@name='toppings']"));
List<WebElement> alloptions = sel.findElements(By.xpath("//select[@name='toppings']//option"));
for (WebElement option: alloptions) {
String optTxt = option.getText();
//System.out.println(optTxt);
if (optTxt.contains(sh1.getRow(3).getCell(1).getStringCellValue())){
option.click();
}
}
}
}
What i am trying to do is as long as there is a value in excel it will loop through excel and the options within the website and keep on selecting all the options using CTRL whose text values are located in excel