Java:调用名称存储在变量中的方法
我有一个要求,例如:
String command = "click"; // this can have value such as clear, getLocation, getSize, getTagName etc.
WebDriver driver = new ChromeDriver(options); //creating a webdriver object
driver.findElement(By.id("id1")).click(); //Here I want "click" method should be called dynamically as per what I have stored in variable `command`.
那么,有没有可能的东西,比如:
driver.findElement(By.id("id1")).<something to call click()>
我已经看过Java中的Reflectm,但根据我的要求,这对我来说很复杂。任何指针都会有所帮助!