您好我正在尝试登录bookmyshow。
首先,我正在从excel表中读取数据,以用户名和密码写入,但在执行时我得到错误
错误:请在类Test_Pack1.Bookmyshow中找不到主要方法 将main方法定义为:public static void main(String [] args) 或JavaFX应用程序类必须扩展 javafx.application.Application
我也提供书面的程序代码。如果我错了,请查看此内容并纠正我。
package Test_Pack1;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.xssf.usermodel.XSSFCell;
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.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class Bookmyshow {
//public static void main()
{
System.setProperty("webdriver.chrome.driver",
"G:\\Selenium_Test\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://in.bookmyshow.com/hyderabad?wzrk_source=Google&wzrk_medium=CPC_Branded&wzrk_campaign=Book_My_Show_Search|RLSA&gclid=CjwKEAiAu6DBBRDDr6-e_6698E0SJACvuxnyBrs85Juwsx_cWiHXrPnS0eKFhZoQmo_nCYgopyDSIxoCGCHw_wcB");
driver.manage().window().maximize();
driver.findElement((By.className("email-input")));
// driver.findElement(By.id("FirstName"));
driver.findElement(By.xpath(".//*[@id='iUserName']")).notifyAll();
}
public static void main(String[] args) throws IOException
{
FileInputStream istream=new FileInputStream("G:\\Selenium_Test\\hari.xlsx");
XSSFWorkbook wrkbook=new XSSFWorkbook(istream);
XSSFSheet sheet1=wrkbook.getSheet("Sheet1");
XSSFRow row=null;
XSSFCell cell=null;
HashMap<String, String> dataHmap = new HashMap<String, String>();
String PropertyName,value;
int lastRowNumber=sheet1.getLastRowNum();
}
}
答案 0 :(得分:0)
您之前评论的部分方式不正确。
首先,您需要作为起点调用的代码应包含在main method
中。您可以从main method
内部依次调用多个方法。我试图改变你的代码位,它应该工作。如果您进一步面对任何问题,请告诉我
package com.automation.servicenow.config;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import org.apache.poi.xssf.usermodel.XSSFCell;
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.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class Bookmyshow {
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver",
"G:\\Selenium_Test\\lib\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.get("https://in.bookmyshow.com/hyderabad?wzrk_source=Google&wzrk_medium=CPC_Branded&wzrk_campaign=Book_My_Show_Search|RLSA&gclid=CjwKEAiAu6DBBRDDr6-e_6698E0SJACvuxnyBrs85Juwsx_cWiHXrPnS0eKFhZoQmo_nCYgopyDSIxoCGCHw_wcB");
driver.manage().window().maximize();
driver.findElement((By.className("email-input")));
// driver.findElement(By.id("FirstName"));
driver.findElement(By.xpath(".//*[@id='iUserName']")).notifyAll();
FileInputStream istream=new FileInputStream("G:\\Selenium_Test\\hari.xlsx");
XSSFWorkbook wrkbook=new XSSFWorkbook(istream);
XSSFSheet sheet1=wrkbook.getSheet("Sheet1");
XSSFRow row=null;
XSSFCell cell=null;
HashMap<String, String> dataHmap = new HashMap<String, String>();
String PropertyName,value;
int lastRowNumber=sheet1.getLastRowNum();
}
}