-1

Is it possible to put variable values from the console inside a database query using Selenium WebDriver?

For example:

//Get the variable from console input
Scanner reader = new Scanner(System.in);
System.out.println("Enter a variable: "); 
String input_variable = reader.next();
reader.close();

//Then do something like this:
String query = "select (input_variable) from database_table";`
2
  • 1
    It looks like you're trying to build a SQL query as a string, for which the linked duplicate is what you're looking for. That said, if it's possible for WebDriver to execute SQL queries against your database, your security model is completely broken. Commented Feb 20, 2018 at 16:07
  • Hi Daniel. Your link fixed my issue. You're right, my question is a duplicate. Thank you. Commented Feb 21, 2018 at 8:03

1 Answer 1

0

There are a few ways you can accomplish this.

String query = String.format("select %s from database_table", variable);

or

String query = "select " + variable.toString() + " from database_table";

are just two examples off the top of my head.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, Andrew, both of these worked! ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.