gpt4 book ai didi

java - 使用Java和sikuli对Excel进行排序并粘贴到网页上

转载 作者:行者123 更新时间:2023-12-02 05:04:33 25 4
gpt4 key购买 nike

我已经编写了上面的代码,每次它都会给我“single”作为输出。

import java.io.FileInputStream;
import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFRow;
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.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.sikuli.basics.Settings;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Screen;

public class teste {

public static void main (String args[]) throws InterruptedException {

try {
// Open the Excel file
FileInputStream fis = new FileInputStream("C:\\test.xls");
// Access the required test data sheet
HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet sheet = wb.getSheetAt(3);
// Loop through all rows in the sheet

for(int count = 0;count<=sheet.getLastRowNum();count++) {

HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));

// Run the test for the current test data row

runTest(row.getCell(3).toString());
}
fis.close();
}
catch (IOException e) {
System.out.println("Test data file not found");
}
}

public static void runTest(String strSearchString) throws InterruptedException {

// Start a browser driver and navigate to Google

WebDriver driver = new FirefoxDriver();

//it will always open private profile

driver.get("http:\\www.google.com");

//Using Sikuli

System.out.println("SCreeeeeen is apppearinggg...wait");
Thread.sleep(5000);
Screen s = new Screen();
Settings.OcrTextSearch = true;
try {
s.click("imgs/Search.png", 0);
System.out.println(strSearchString + " ppp ");
s.type(strSearchString);
s.doubleClick("imgs/GSearch.png", 0);
Thread.sleep(5000);

}
catch(FindFailed e){
e.printStackTrace();
}

Thread.sleep(1000);

driver.quit();
}
}

这是要排序的 Excel 工作表,我在这里陷入困境,因为如果 Excel 中的国家/地区列是英国或我们,我需要搜索“类型”。

This is the excel sheet which is to be sorted and here I am stuck because I need to search "Type" if the country column from excel is uk or us

最佳答案

在代码中,您似乎每次都使用同一行...

for(int count = 0;count<=sheet.getLastRowNum();count++){

HSSFRow row = sheet.getRow(4);
HSSFCell cell = row.getCell(4);
System.out.println("Running test case " + cell.getStringCellValue().equalsIgnoreCase("uk"));

对于每个循环,您将行值保持为 4 硬编码,它在整个循环中保持不变。

即对于计数 = 0,

HSSFRow row = Sheet.getRow(4);

对于count =1

又是HSSFRow row =sheet.getRow(4);

相反,你需要这样做

HSSFRow row = sheet.getRow(count);

试试这个...

关于java - 使用Java和sikuli对Excel进行排序并粘贴到网页上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27916936/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com