我所试图做的是从这个例子网站选择多个选项按住CTRL选择多个选项,并选择值会从Excel
http://www.htmlcodetutorial.com/forms/_SELECT_MULTIPLE.html
多重选择值将来自Excel中,虽然,手段如果excel行的值分别为不同行(同一列中)的蘑菇,洋葱和橄榄,则只会在页面内逐一选择这些值。 Excel文件看起来是这样的:
http://i.imgur.com/tcEB2wX.png
这是我到目前为止的代码高达
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();
}
}
}
}
什么,我试图做的,只要有在Excel中它的值是将通过excel和网站中的选项进行循环,并继续使用其文本值位于excel中的CTRL选择所有选项。
欢迎来到SO。我不能完全理解你的问题。你的代码中哪里找到错误或问题? – nbayly
对不起,更新了这个问题。我想要做的是只要在Excel中有一个值,它将通过excel和网站中的选项循环,并继续使用CTRL的选择所有选项,其文本值位于excel – Ami