我正在尝试制作一个selenium程序在特定网站上线,登录,然后在搜索框中放置我从excel文件中获取的地点和地址,并在搜索完成后添加评论但是,有些地方已经过审核,无法再次审核,所以我的问题是当一个地方被审查如何再次搜索但是从NEXT excel单元格获取信息而不是使用相同的地方?我知道那里有可能是一个简单的答案,但我无法弄清楚如何更具体地搜索它。我希望你能帮助我。这是我的所有代码。
public class Checkbot {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
try {
//Open excel file
String FilePath = "C:\\Users\\CandyGirl\\Documents\\DunkinDonuts1.6.2.xlsx";
FileInputStream fs = new FileInputStream(FilePath);
XSSFWorkbook wb = new XSSFWorkbook(fs);
//Access data sheet
Sheet sh = wb.getSheet("Sheet6");
//Loop through rows
for( int count = 0;count <=sh.getLastRowNum();count++){
Row row = sh.getRow(count);
runTest(row.getCell(0).toString(),row.getCell(1).toString());
boolean reviewed;
if(reviewed = true){
count++;
}
}
fs.close();
}catch(IOException e){
System.out.println("Test data file not found");
}
}
private static void runTest(String searchWhat, String searchWhere) throws InterruptedException {
// TODO Auto-generated method stub
//Start browser driver to axs map website
WebDriver driver = new ChromeDriver();
driver.get("http://www.axsmap.com/");
//log in
//click Log In button
driver.findElement(By.id("nav-login")).click();
//Enter username
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(username);
//Enter password
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password);
//Press Enter to log in
WebElement input = driver.findElement(By.id("password"));
input.submit();
//try to make it wait before it crashes
waitForLoad(driver);
//if after the login the page shows an application error just go back to the main page
boolean myTitle = driver.getTitle().contains("Application Error");
if (myTitle = true){
driver.get("http://www.axsmap.com/");}
//Enter search what and where and send it
searchPlace(searchWhat, searchWhere, driver);
//try to make it wait to load,if there's an error go back to front page and try again.
waitForLoad(driver);
if (myTitle = true){
driver.get("http://www.axsmap.com/");
searchPlace(searchWhat,searchWhere,driver);}
//when page loads to the map click add review
driver.findElement(By.id("btn-add-review")).click();
//If reviewed
waitForLoad(driver);
boolean reviewed = driver.findElement(By.cssSelector("#pg-addreview > div > div > div.w-form.venue-review-form > div")).isDisplayed();
if (driver.findElement(By.cssSelector("#pg-addreview > div > div > div.w-form.venue-review-form > div")).isDisplayed()){
searchPlace(searchWhat,searchWhere,driver);}
//find and click on the 4 star rating
driver.findElement(By.cssSelector("#pg-addreview > div > div > div.w-form.venue-review-form > form > div:nth-child(2) > div > div > div.row-value.w-col.w-col-9.entry-stars > div:nth-child(6)")).click();
driver.close();
}
private static void searchPlace(String searchWhat, String searchWhere, WebDriver driver) {
//Find and type in the search What field
driver.findElement(By.id("search-what")).clear();
WebElement element = driver.findElement(By.id("search-what"));
element.sendKeys(searchWhat);
//Find and type in the search Where field and press enter
driver.findElement(By.id("search-where")).clear();
driver.findElement(By.id("search-where")).sendKeys(searchWhere);
element.submit();
}
public static void waitForLoad(WebDriver driver) {
ExpectedCondition<Boolean> pageLoadCondition = new
ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
}
};
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(pageLoadCondition);
}
}