lundi 28 janvier 2019

Unable to get method via Reflection

would love some help from experts here. I am getting the following error : enter image description here

The following is my code:

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);
 }  

The issue is at the 2nd last line of code, where the error occurs. The method in question is in another class, and what that line is trying to do is basically return to the main class (TC_PaymentChannel_FF.java) that calls this class (where the above code is in) and run the method (VerifyPaymentChannel) in that main class.

Hope to have advice.





Aucun commentaire:

Enregistrer un commentaire