在下面的代碼中,我想要在兩個不同的單元格中傳遞兩個數據。 (單元格1和單元格2)。但它僅顯示單元格1的數據。有人請幫助。使用硒webdriver在不同的Excel單元格中寫入多個數據
import java.io.FileOutputStream;
import java.util.concurrent.TimeUnit;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class xl {
private WebDriver driver;
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void test() throws Exception {
driver.get("http://www.google.com/");
String s = driver.getTitle();
writereport(0,0,s);
writereport(1,1,"Valid");
}
@After
public void tearDown() throws Exception {
driver.quit();
}
public void writereport(int a,int b,String text)
{
try
{
FileOutputStream f = new FileOutputStream("C:\\DEMO.xls",true);
WritableWorkbook book = Workbook.createWorkbook(f);
WritableSheet sheet = book.createSheet("TESTRESULTS",0);
Label i = new Label(a, b, text);
sheet.addCell(i);
book.write();
book.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}}
我試圖 標籤I =新標籤(A,B,文本); sheet.addCell(i); 標籤P =新標籤(a,b,文本); sheet.addCell(p); 但是沒有運氣
希望這代碼幫你做的更好代碼much.Its。 –