我能够从 Oracle 数据库中获取特定的列值,并将该值填充到网页上的特定字段中,如下所示。但是,我无法弄清楚如何从 Oracle 数据库表中获取特定的单元格值并将该值填充到网页上的特定字段中。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.Test;
public class ProApp extends BaseClass {
@Test(priority = 2)
public void setUpConnection() throws ClassNotFoundException, SQLException, FileNotFoundException, InterruptedException, IOException {
String driver_DBPath = "jdbc:oracle:thin:@Host:Port:SID";
String DB_username = "*****";
String DB_password = "*****";
String Query = "select * from TestTable";
Connection con = DriverManager.getConnection(driver_DBPath, DB_username, DB_password);
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(Query);
while (rs.next()) {
String Email = rs.getString("CLAIM_NUMBER");
String Pwd = rs.getString("INDIVIDUAL_NUM");
testUserNamePassword(Email, Pwd);
}
}
@Test(priority = 1)
public void clickLoginLink() throws InterruptedException, IOException {
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") + "\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
driver.findElement(By.xpath(obj.getProperty("ClickOnLoginLink"))).click();
Thread.sleep(1000);
}
@Test(priority = 3)
public void testUserNamePassword(String Email1, String Pwd1) throws InterruptedException, IOException {
Properties obj = new Properties();
FileInputStream objfile = new FileInputStream(System.getProperty("user.dir") + "\\src\\com\\provider\\Object.Properties");
obj.load(objfile);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Email1"))).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Email1"))).sendKeys(Email1);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Pwd1"))).clear();
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Pwd1"))).sendKeys(Pwd1);
Thread.sleep(1000);
driver.findElement(By.xpath(obj.getProperty("Submit"))).click();
Thread.sleep(1000);
}
}