本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElementByName方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElementByName方法的具体用法?C# ChromeDriver.FindElementByName怎么用?C# ChromeDriver.FindElementByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElementByName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Index
public ActionResult Index()
{
var driver = new ChromeDriver();
//driver.Navigate().GoToUrl("http://diesel.elcat.kg");
driver.Navigate().GoToUrl("http://diesel.elcat.kg/index.php?act=Login");
// Get the page elements
var userNameField = driver.FindElementByName("UserName");
var userPasswordField = driver.FindElementByName("PassWord");
var loginButton = driver.FindElementByXPath("//input[@name='submit']");
// Type user name and password
userNameField.SendKeys("bishkek312");
userPasswordField.SendKeys("8061");
// and click the login button
loginButton.Click();
driver.Navigate().GoToUrl("http://diesel.elcat.kg/index.php?showtopic=43884872");
DeleteLastUp(driver);
var messageField = driver.FindElementById("fast-reply_textarea");
messageField.SendKeys(upMessageValue);
var sendButton = driver.FindElementByXPath("//input[@value='Отправить']");
return new EmptyResult();
//return View();
}
示例2: Register
public static void Register(BackgroundWorker worker, string name, string password, IList<string> barcodes)
{
driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://7777.bg/user/lottery_tickets/register/");
driver.FindElementByName("login_username").SendKeys(name);
driver.FindElementByName("login_password").SendKeys(password);
driver.FindElementByXPath("//input[@type='submit']").Click();
Wait(driver);
var barcodeTextBox = driver.FindElementByName("register_number");
var submitButton = driver.FindElementByXPath("//button[@type='submit']");
int progressPercentage = Convert.ToInt32(100 / barcodes.Count);
for (int i = 0; i < barcodes.Count; i++)
{
barcodeTextBox.SendKeys(barcodes[i]);
submitButton.Click();
Thread.Sleep(1000);
var finishButton = driver.FindElementByXPath("//a[@href='javascript:void(0);']");
finishButton.Click();
worker.ReportProgress(progressPercentage * (i + 1));
Thread.Sleep(1000);
}
}
示例3: Main
static void Main(string[] args)
{
var driver = new ChromeDriver(); // Should work in other Browser Drivers
string baseLink = "http://www.codeproject.com";
//foreach (var link in links)
for (int i = 2326; i > 2325; i--)
{
string link = baseLink + i.ToString();
driver.Navigate().GoToUrl(link);
try
{
var login = driver.FindElementById("Button1");
var uName = driver.FindElementByName("lname");
var pass = driver.FindElementByName("passw");
uName.SendKeys("admin");
pass.SendKeys("*******");
login.Submit();
}
catch
{
//already logged in
}
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
//Use it as you want now
string screenshot = ss.AsBase64EncodedString;
byte[] screenshotAsByteArray = ss.AsByteArray;
FileNameFromURL fileNameFromURL = new ConsoleApplication1.FileNameFromURL();
string filePath = Application.StartupPath + fileNameFromURL.ConvertToWindowsFileName(link) + ".jpg";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
ss.SaveAsFile(filePath, ImageFormat.Png); //use any of the built in image formating
ss.ToString();//same as string screenshot = ss.AsBase64EncodedString;
}
//driver.Dispose();
driver.Close();
}
示例4: Main
static void Main(string[] args)
{
//Declaration
//l = phone numbers, quotation number, desc of the records, entity, submission date , submission time, name of user
List<string> l = new List<string>();
List<string> quotation = new List<string>();
List<string> desc = new List<string>();
List<string> entity = new List<string>();
List<string> subDate = new List<string>();
List<string> subTime = new List<string>();
List<string> name = new List<string>();
List<string> kw = new List<string>();
Dictionary<string, string> dict = new Dictionary<string, string>();
int numbrecords = 0;
string filename = "";
#region Load google chrome
// Initialize the Chrome Driver
using (var driver = new ChromeDriver())
{
LoadFile(ref l, ref dict);
// Go to the home page
driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
#region autofill and extract data from GeBiz webpage
foreach (var val in l)
{
//Get the page elements
var fromdate = driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[2]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[5]/td[4]/input");
var todate = driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[2]/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[5]/td[6]/input");
var keyword = driver.FindElementByName("searchByDesc");
new SelectElement(driver.FindElement(By.Name("dateType"))).SelectByIndex(1);
var submitbutton = driver.FindElementByName("submitAction");
fromdate.SendKeys(DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy"));
todate.SendKeys(DateTime.Now.AddDays(-1).ToString("dd/MM/yyyy"));
keyword.SendKeys(val);
//click the submit button
submitbutton.Click();
if (driver.FindElements(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td")).Count == 1)
{
driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
}
else
{
if (driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td").Text.Equals("No data found"))
{
Console.WriteLine("No Data Found");
driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
}
else
{
#region Checking the number of records
for (int j = 11; j > 1; j--)
{
//select the records by row
if (driver.FindElements(By.XPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + j + "]")).Count == 1)
{
Console.WriteLine(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[2]/td").Text);
numbrecords = j + 1;
#region Storing quotation and desc to list
for (int i = 2; i < numbrecords; i++)
{
//get the record from the current row on the quotation col
quotation.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[2]/table/tbody/tr[1]/td/a/b").Text);
//get the record from the current row on the description col
desc.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[3]/table/tbody/tr[1]/td").Text);
//get the record from the current row on entity from description col
entity.Add(RemoveWord(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[3]/table/tbody/tr[2]/td").Text));
//get the record from the current row on submission date from closing date/time col
subDate.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[5]/table/tbody/tr[1]/td").Text);
//get the record from the current row on submission time from closing date/time col
subTime.Add(driver.FindElementByXPath("/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td/form/table[3]/tbody/tr/td/table[1]/tbody/tr[" + i + "]/td[5]/table/tbody/tr[2]/td").Text);
//add the name of the organisation that the keyword belong to
name.Add(dict[val]);
//add the keyword
kw.Add(val);
}
driver.Navigate().GoToUrl("http://www.gebiz.gov.sg/scripts/main.do?sourceLocation=openarea&select=tenderId");
break;
#endregion
}
}
#endregion
}
}
}
#endregion
}
#endregion
//saving to excel file
filename = SaveExcel();
ExportData(filename, ref quotation, ref desc, ref entity, ref subDate, ref subTime, ref name, ref kw);
//.........这里部分代码省略.........
示例5: RetrieveSelectedBankAccountDetails
public CommunicationsResponse RetrieveSelectedBankAccountDetails(BankCommsCapsule capsule)
{
string address = "https://online.mbank.pl/pl/Login";
CommunicationsResponse response = new CommunicationsResponse();
ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl(address);
// WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
Thread.Sleep(3000);
IWebElement login = driver.FindElementByName("userID");
IWebElement password = driver.FindElementByName("pass");
login.SendKeys(capsule._login);
password.SendKeys(capsule._password);
password.Submit();
driver.Navigate().GoToUrl("https://online.mbank.pl/pl#/accounts");
Thread.Sleep(3000);
// IWebElement account = driver.FindElementByName
driver.Quit();
return response;
}
示例6: ButtonByName
public void ButtonByName(string path, ChromeDriver driver)
{
var button = driver.FindElementByName(path);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
button.Click();
}