I'm trying to write a Selenium java program that will take commands from an external source. e.g. I have externally wrote driver.findElement(By.id("username")).sendKeys("FirstName");
in a user friendly way so users can create selenium scripts without knowing the back end code.
Splitting it up into 4 sections:
1) identifier type e.g. id
2) identifier e.g. "username"
3) command type e.g. sendKeys
4) input data e.g. "Firstname"
In my code I am using a Runtime Compiler to compile String as code (I'm doing this as I can manipulate the entire code as string as it runs) this way I can have a small section of code to run anything referenced in the external source, so this code will work for sendKeys, click etc etc without needing any changes as long as the external source is created correctly.
I am able to run
`" String URL2 = \"id\";" + "\n" +
" String URL3 = \"username\";" + "\n" +
" String URL4 = \"sendKeys\";" + "\n" +
" String URL5 = \"Grabhamn\";" + "\n" +
" System.out.println(\"driver.findElement(By.\"+URL2+\"
(\"+URL3+\")).\"+URL4+\"(\"+URL5+\");\");" + "\n" +`
This outputs driver.findElement(By.id(username)).sendKeys(Grabhamn);
but my problem is then how do I execute this code in the runtime Compiler. Also, I need the code to output as
driver.findElement(By.id("username")).sendKeys("Grabhamn");
containing quotation marks in these places as I've been unsuccessful to do this also.
Any information on how to do this or alternative solutions will be much appreciated.