[英]C# Console Selenium | Read lines from text file
I have created ac# console application using Selenium with Chrome Drivers. 我已经使用Selenium和Chrome Drivers创建了ac#控制台应用程序。 This is something that i am wondering if i can have some help on.
这是我想知道是否可以提供帮助的东西。 Essentially i want to create something where there will be a emails.txt file and within that file the user places an email (example) example@gmail.com and they then make a new line with another email example2@gmail.com .
本质上,我想创建一个将有一个emails.txt文件的东西,并且用户在该文件中放置一个电子邮件(示例) example@gmail.com ,然后他们与另一个电子邮件example2@gmail.com换行。 So on....Basically once they have added that within the emails.txt on the website i am automating there is an email field.
依此类推......基本上,一旦他们在网站上的emails.txt中添加了该内容 ,我就会自动执行一个电子邮件字段。 I am wondering if i can make it so that on the first line of emails it will run the first auto form filling, then on the second line of emails it will open a brand new driver window and doing the same thing.
我想知道是否可以做到这一点,以便在电子邮件的第一行将运行第一个自动表单填充,然后在电子邮件的第二行将打开一个全新的驱动程序窗口并执行相同的操作。
I could not find anything like this as such on the internet so some help and direction would be great. 我在互联网上找不到像这样的东西,所以一些帮助和指导将是很棒的。
Let's have a Form
class that represents the form you want to fill: 让我们有一个
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
}
}
Then there's the Main
method that reads the emails from file, creates new forms and fills them with the emails: 然后是
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.