我想爲問題創建多個答案,在Excel中,對於問題1,我有3行,包含答案1,答案2和答案3。希望根據問題名稱重複回答3次。由於我使用Apache POI從Excel中檢索值,因此我的代碼適用於第一行,但當它移動到第二行時,它也會嘗試輸入問題。Selenium Webdriver - Java - 如何將從excel中讀取的值存儲在臨時變量中
我想在臨時變量中存儲第1行的問題名稱,當循環到達第2行時,它應該將臨時變量中的值與第2行問題名稱進行比較。如果問題的名稱相同,則不應重複輸入問題,代碼應僅創建答案。你能幫忙嗎?下面是我使用的代碼
driver.get(new URI(driver.getCurrentUrl()).resolve("https://stackoverflow.com/questions/question/create").toString());
WaituntilElementpresent.isExist();
for (int j=1; j <= sheet1.getLastRowNum(); j++)
{
String question_name = sheet1.getRow(j).getCell(0).getStringCellValue();
String question_text = sheet1.getRow(j).getCell(1).getStringCellValue();
String question_type = sheet1.getRow(j).getCell(2).getStringCellValue();
String question_naire = sheet1.getRow(j).getCell(3).getStringCellValue();
String answer_name = sheet1.getRow(j).getCell(4).getStringCellValue();
String answer_value_fillup = sheet1.getRow(j).getCell(5).getStringCellValue();
int answer_value_int = (int) sheet1.getRow(j).getCell(6).getNumericCellValue();
double answer_value_deci = sheet1.getRow(j).getCell(7).getNumericCellValue();
String answer_weight = sheet1.getRow(j).getCell(8).getStringCellValue();
String answer_comparison = sheet1.getRow(j).getCell(9).getStringCellValue();
String response_text = sheet1.getRow(j).getCell(10).getStringCellValue();
String option_text = sheet1.getRow(j).getCell(11).getStringCellValue();
String option_correct = sheet1.getRow(j).getCell(12).getStringCellValue();
WaituntilElementpresent.isExist();
//Boolean ques_name = driver.getPageSource().matches(question_name);
String ques_name= driver.findElement(By.id("name")).getText();
//String ques_name1= sheet1.getTopRow().getCell(0).getStringCellValue();;
WaituntilElementpresent.isExist();
System.out.println("Question name from Webpage -->"+ques_name);
System.out.println("Excel Question name -->"+question_name);
Thread.sleep(5000);
if (ques_name != question_name)
{
//Call the method
add_question_page.Add_Question_MI(driver,question_name,question_text,question_type,question_naire);
WaituntilElementpresent.isExist();
} //for if
String parentWindowHandler = driver.getWindowHandle();
add_question_page.Add_Answer_MI(driver);
WaituntilElementpresent.isExist();
CallAnswer(driver);
WaituntilElementpresent.isExist();
CallAnswerbasedonQuestiontype(driver,question_type, answer_name,answer_value_fillup,answer_value_int,answer_value_deci,answer_weight,answer_comparison,response_text,option_text, option_correct);
WaituntilElementpresent.isExist();
add_question_page.Save_Answer_MI(driver,parentWindowHandler);
} //for j
謝謝Sudharsan !!它的工作 – Selvi
很高興它的工作:) –