这个 ?
如果您的类名为 String
public <T> T SelectTab(WebDriver driver,String path, T className) throws Exception{
driver.findelement(By.xpath("path")).click();
return PageFactory.initElements(driver, className.class);
}
并将 SelectTab 称为
SelectTAB(driver,path,Class.forName(classNameString));// where classNameString is the value you are currently passing to SelectTab with your code.
或者使用类似的东西
public Object SelectTab(WebDriver driver,String path, String className) throws Exception{
driver.findelement(By.xpath("path")).click();
return PageFactory.initElements(driver, Class.forName(className));
}