我正在運行以下代碼,並顯示「搜索框無法解析」的錯誤,如何解決此問題?請幫助。我無法找到我獲取此內容的原因錯誤感謝提前:)「searchbox」變量無法解析錯誤
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class DataDriven_Ex {
public static void main(String[] args) {
FirefoxDriver driver = new FirefoxDriver();
driver.get("http://www.amazon.in");
WebElement searchbox = driver.findElement(By.xpath("//*[@id='twotabsearchtextbox']"));
}
@Test
public void test() throws Exception {
File file = new File("F://Selenium excel//DataDriven.xlsx");
FileInputStream fs = new FileInputStream(file);
XSSFWorkbook wb = new XSSFWorkbook(fs);
XSSFSheet sh = wb.getSheet("Sheet1");
int rowcount = sh.getLastRowNum();
for (int i = 0; i<=rowcount;i++)
{
String keyword = sh.getRow(i).getCell(0).getStringCellValue();
searchbox.sendKeys(keyword);
searchbox.submit();
}
}
}
謝謝....代碼現在工作:) – Priyanka