I wrote a program where values are coming from sql database.Now i want to send those values to frontend using selenium. say it is an pincode i fetched from Database but now if locate the element where i want to store that fetched otp how will I do?.sendkeys in selenium is not accepting Piece of code I wrote : import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement;
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver;
public class JavaConnect2SQL {
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class JavaConnect2SQL {
public static void main(String[] args) throws ClassNotFoundException {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
// TODO Auto-generated method stub
//String url="jdbc:sqlserver://LAPTOP-F0E1C4GT\SQLEXPRESS;databaseName=BikeStores;"; //String user="sa"; //String password="NewPassword@123";
String url = "jdbc:sqlserver://localhost;user=sa;password=NewPassword@123;databaseName=BikeStores"; //connServer.connect(url);
//String url="jdbc:sqlserver://LAPTOP-F0E1C4GT\\SQLEXPRESS;databaseName=BikeStores;";
//String user="sa";
//String password="NewPassword@123";
String url = "jdbc:sqlserver://localhost;user=sa;password=NewPassword@123;databaseName=BikeStores";
//connServer.connect(url);
Connection connection=DriverManager.getConnection(url);
System.out.println("Connected");
Statement statement = connection.createStatement();
String query = "select TOP 1 pincode from pintable";
ResultSet rs = statement.executeQuery(query);
while(rs.next()){
System.out.println(rs.getString(1));
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
driver.navigate().to("https://indialends.com/");
driver.findElement(By.linkText("Personal Loan")).click();
//driver.findElement(By.name("li_display_name")).toString(rs.getString(1));
//Belowline->Is my confusion??
driver.findElement(By.name("pincode")).sendKeys("122018");//this 122018 i am writing by sendkeys but i want this to be filled from SQL itself
} }catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("Oops,there is error");
e.printStackTrace();
}
}
}
driver.findElement(By.name("pincode")).sendKeys("122018");//this 122018 i am writing by sendkeys but i want this to be filled from SQL itself
} }catch (SQLException e) { // TODO Auto-generated catch block System.out.println("Oops,there is error"); e.printStackTrace(); } } }