我想了解反射如何工作,我無法找出問題所在。在第二個循環中,method.length
不是從另一個程序中獲取方法。在硒中的java反射
以下是代碼:
public class DriverScript
{
public static ActionKeywords actionKeywords;
public static String sActionKeyword;
public static Method method[];
public DriverScript() throws NoSuchMethodException, SecurityException
{
actionKeywords = new ActionKeywords();
method = actionKeywords.getClass().getMethods();
}
public static void main(String[] args) throws Exception
{
System.out.println(method);
String sPath = "C:\\Users\\mag6\\Desktop\\toolsqa.xlsx";
ExcelUtils.setExcelFile(sPath, "Test Steps");
for (int iRow = 1; iRow <= 9; iRow++)
{
sActionKeyword = ExcelUtils.getCellData(iRow, 3);
execute_Actions();
}
}
private static void execute_Actions() throws Exception
{
for (int i = 0; i < 11; i++)
{
if (method[i].getName().equals(sActionKeyword))
{
method[i].invoke(actionKeywords);
break;
}
}
}
}
https://stackoverflow.com/questions/29250410/get-methods-using-java-reflection-class **指這個** – selvakumar
沒有大膽的應在那裏。 –