无法通过反射获取方法

时间:2019-01-28 10:47:32

标签: java reflection

希望这里的专家为您提供帮助。我收到以下错误:

enter image description here

以下是我的代码:

public void MainMenu_Gold(WebDriver driver, String browser, String method ,String Xpath, String Amount, String TFA, String Code, String Cancel, String OK) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException, InterruptedException{

    Class[] arg = new Class[12];
    arg[0] = WebDriver.class;
    arg[1] = String.class;      
    arg[2] = String.class;  
    arg[3] = String.class;
    arg[4] = String.class;
    arg[5] = String.class;  
    arg[6] = String.class;  
    arg[7] = String.class;    
    arg[8] = String.class;
    arg[9] = String.class;
    arg[10] = String.class;
    arg[11] = String.class;
    Class<?> cls = Class.forName(browser); 
    Object obj = cls.newInstance(); 
    Thread.sleep(10000);
    driver.findElement(By.xpath("//*[@id='nav_collapse']/ul/li[1]/a")).click();
    Thread.sleep(10000);
    driver.findElement(By.linkText("Reload Now")).click();
    points_before_Str = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[1]/div/div/div[2]/div/span[1]")).getText(); // get the points detail before reload    
    Convert_Points_Str_Dou(points_before_Str);//call the method to convert String to Double
    Points_Before = points_before_String;
    balance_before_Str = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[1]/div/div/div[2]/div/span[2]")).getText(); //get the monetary value before reload
    Convert_Balance_Str_Dou(balance_before_Str);    
    Thread.sleep(10000);
    driver.findElement(By.xpath(Xpath)).click();
    //driver.findElement(By.cssSelector("img[@alt='Hong Leong Connect']")).click();
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("window.scrollBy(0,500)", "");
    Thread.sleep(5000);

    driver.findElement(By.xpath("//*[@id='amount']")).sendKeys(Amount); //Assume minimum amount is met.     
    //Text_Not_Enough = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[3]/div[2]/div[1]/div/p[2]")).getText();  
    driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[3]/div[2]/div[2]/div[2]/div/a")).click();//click on Next after key in amount
    Thread.sleep(5000);
    driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[3]/div[2]/div[2]/div/div/div/div/div[2]/div/span/a[1]")).click(); // Choose backup code option
    System.out.println("Code = " + Code);
    driver.findElement(By.xpath("//*[@id='code']")).sendKeys(Code);//key in backup code
    driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div/div[3]/div[2]/div[3]/div[2]/div[2]/button")).click();
    //At this point, directing to payment channle 3rd party side
    Thread.sleep(10000);
    driver.findElement(By.xpath(Cancel)).click(); //Click on cancel button on 3rd part payment page
    driver.findElement(By.xpath(OK)).click();//Click on OK Button to return to confirm Cancel
    Thread.sleep(20000);
    Reload_Pending = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div[1]/div/h4")).getText();  
    Points_After = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div[3]/div/div/div[1]/div/div[2]/div/span[1]")).getText();
    Balance_After = driver.findElement(By.xpath("//*[@id='main']/body/div[1]/main/div/div[3]/div/div/div[1]/div/div[2]/div/span[2]")).getText();
    System.out.println("Before Method methos1, method = " + method);
    Method method1 = cls.getMethod(method, arg[0], arg[1], arg[2],arg[3],arg[4],arg[5],arg[6],arg[7],arg[8],arg[9],arg[10],arg[11]);        
    method1.invoke(obj, driver, browser, Xpath, Amount, TFA, Code, Cancel, OK, Points_Before, Reload_Pending, Points_After);
 }  

问题出在代码的第二行,发生错误。有问题的方法在另一个类中,而该行试图做的基本上是返回到调用该类(上面的代码在其中)的主类(TC_PaymentChannel_FF.java)并在其中运行方法(VerifyPaymentChannel)主班。

希望有意见。

0 个答案:

没有答案