How can I print the line in the txt file drawn in the void txt()
method, inside the driver.get()
parentheses in void link()
with quotes?
I want to get a link from the txt file and let the automatic program enter the site.
Thanks for your help.
package test2;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.BufferedReader;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
public class test2 {
public WebDriver driver = new ChromeDriver();
public Actions action = new Actions(driver);
public static String rows = "";
public void link() throws InterruptedException {
// driver.get("https://www.google.com/");
//How can I type here,taken row from the TXT file in the quotes("")?
driver.get(rows);
Thread.sleep(3000);
}
public void txt() throws IOException {
// open the LinkAl txt file
File file = new File("LinkAl.txt");
BufferedReader reader = null;
reader = new BufferedReader(new FileReader(file));
int i=0;
rows = reader.readLine();
while (rows!=null) {
i++;
// Get the second row to the LinkAl txt file
if(i==2)
{
System.out.println(rows);
}
rows = reader.readLine();
}
}
public void driverquit() {
driver.quit();
}
public static void main(String[] args) throws InterruptedException, IOException {
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver_win32\\chromedriver.exe");
test2 Links = new test2();
// Links.link();
Links.txt();
Links.driverquit();
}
}
Change your below method like mentioned to read file line by line till EOF.
public void txt() throws IOException {
// open the LinkAl txt file
File file = new File("LinkAl.txt");
String line="";
BufferedReader reader = null;
reader = new BufferedReader(new FileReader(file));
while ((line = reader.readLine()) != null) {
// System.out.println(line);
link(line);
}
}
Also if you want to pass the read line to link method change it as below
public void link(String line) throws InterruptedException {
System.out.println("Dosyadançekilenlerveriler: " + line);
// driver.get("https://www.google.com/");
driver.get(line);
Thread.sleep(3000);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.