本文整理汇总了C#中OpenQA.Selenium.Chrome.ChromeDriver.FindElementByXPath方法的典型用法代码示例。如果您正苦于以下问题:C# ChromeDriver.FindElementByXPath方法的具体用法?C# ChromeDriver.FindElementByXPath怎么用?C# ChromeDriver.FindElementByXPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Chrome.ChromeDriver
的用法示例。
在下文中一共展示了ChromeDriver.FindElementByXPath方法的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: IfEmailAddressIsNotValid_ShowValidationMessage
public void IfEmailAddressIsNotValid_ShowValidationMessage()
{
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://localhost:49333/Account/Login");
var loginErrorMessage1 = driver.FindElementsByXPath("//*[@id='loginForm']/form/div[1]/div/span/span");
Assert.AreEqual(0, loginErrorMessage1.Count);
driver.FindElementByXPath("//*[@id='loginForm']/form/div[4]/div/input").Click();
var loginErrorMessage = driver.FindElementByXPath("//*[@id='loginForm']/form/div[1]/div/span/span");
Assert.True(loginErrorMessage.Displayed);
}
}
示例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: InputInfo
public void InputInfo(string path, string information, ChromeDriver driver)
{
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
var Input = driver.FindElementByXPath(path);
Input.SendKeys(information);
}
示例6: Button
public void Button(string path, ChromeDriver driver)
{
var button = driver.FindElementByXPath(path);
driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
button.Click();
}