[英]C# Console Selenium | Read lines from text file
我已經使用Selenium和Chrome Drivers創建了ac#控制台應用程序。 這是我想知道是否可以提供幫助的東西。 本質上,我想創建一個將有一個emails.txt文件的東西,並且用戶在該文件中放置一個電子郵件(示例) example@gmail.com ,然后他們與另一個電子郵件example2@gmail.com換行。 依此類推......基本上,一旦他們在網站上的emails.txt中添加了該內容 ,我就會自動執行一個電子郵件字段。 我想知道是否可以做到這一點,以便在電子郵件的第一行將運行第一個自動表單填充,然后在電子郵件的第二行將打開一個全新的驅動程序窗口並執行相同的操作。
我在互聯網上找不到像這樣的東西,所以一些幫助和指導將是很棒的。
讓我們有一個Form
類,它代表您要填寫的表單:
public class Form
{
private readonly IWebDriver _driver;
public Form(IWebDriver driver)
{
_driver = driver;
}
public void Fill(string email)
{
// this is where you use the driver to access the form fields and set their contents
}
}
然后是Main
方法, Main
方法從文件中讀取電子郵件,創建新表單並用電子郵件填充它們:
public static void Main()
{
var emails = File.ReadAllLines("emails.txt");
foreach (var email in emails)
{
using (var driver = ... )// todo create new chrome driver instance
{
// todo use the driver to navigate to the page where the form is
var form = new Form(driver);
form.Fill(email);
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.