本文整理汇总了C#中OpenQA.Selenium.Firefox.FirefoxDriver.FindElement方法的典型用法代码示例。如果您正苦于以下问题:C# FirefoxDriver.FindElement方法的具体用法?C# FirefoxDriver.FindElement怎么用?C# FirefoxDriver.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Firefox.FirefoxDriver
的用法示例。
在下文中一共展示了FirefoxDriver.FindElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoginToSBM
public static bool LoginToSBM(string siteToTest, string sbmUserName, string sbmUserPass)
{
///We will open that URL and will be performing test over it
///string siteToTest = "http://stl-alms-tst4/workcenter/tmtrack.dll?shell=swc";
///SBM credentials
/// string sbmUserName = "admin";
/// string sbmUserPass = "";
/// Open the site and wait 5 second while the site is loaded
IWebDriver drv = new FirefoxDriver();
///drv.Navigate().GoToUrl("http://stl-qa-oalmt1/workcenter/tmtrack.dll?shell=swc");
drv.Navigate().GoToUrl(siteToTest);
System.Threading.Thread.Sleep(5000);
///find login form Username field and send sbmUserName variable content (string)
IWebElement sbmLoginUName = drv.FindElement(By.Id("authUID"));
sbmLoginUName.Clear();
sbmLoginUName.SendKeys(sbmUserName);
IWebElement sbmLoginUPass = drv.FindElement(By.Id("authPWD"));
sbmLoginUPass.Clear();
sbmLoginUPass.SendKeys(sbmUserPass);
IWebElement sbmLoginBtn = drv.FindElement(By.Id("logonButton"));
sbmLoginBtn.Click();
IWebElement foh = drv.FindElement(By.CssSelector("div.cd-more-info:nth-child(1) > p:nth-child(2) > a:nth-child(3)"));
Assert.AreEqual("Full online help",foh,true);
return true;
}
示例2: RunSalesExecutive
// GET: RunSystemAdministrator
public ActionResult RunSalesExecutive()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:4601/");
var emp = _employeeService
.Queryable()
.Where(x => x.DepartmentRoleId == 10)
.FirstOrDefault ();
emp.EmployeeLogin = _employeeLoginService
.Queryable()
.Where(x => x.EmployeeId == emp.EmployeeId)
.FirstOrDefault();
IWebElement UserName = driver.FindElement(By.Name("UserName"));
IWebElement Password = driver.FindElement(By.Name("Password"));
var loginButton = driver.FindElement(By.XPath("/html/body/div/div/div/section/form/button"));
UserName.SendKeys(emp.EmployeeLogin.UserName);
Password.SendKeys(emp.EmployeeLogin.Password);
loginButton.Click();
Timer timer = new Timer(1000);
timer.Start();
timer.Stop();
return View();
}
示例3: Main
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(@"http://www.weibo.com");
WebDriverWait waitPageOpen = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
IWebElement inpt_username = waitPageOpen.Until<IWebElement>((d) => { return d.FindElement(By.Name("username")); });
waitPageOpen.Until((d) => { return inpt_username.Displayed; });
inpt_username.SendKeys(@"[email protected]");
IWebElement inpt_pwd = driver.FindElement(By.Name("password"));
inpt_pwd.SendKeys(@"kodakpdc2000");
IWebElement btn_login = driver.FindElement(By.ClassName("W_btn_g"));
btn_login.Click();
waitPageOpen.Until((d)=>{return d.Title.StartsWith("我的首页");});
//IList<IWebElement> personInfos = driver.FindElements(By.ClassName("user_atten"));
//if (personInfos.Count == 1)
//{ personInfos[0].FindElement(By.PartialLinkText("粉丝")).Click(); }
IWebElement temp = driver.FindElement(By.PartialLinkText("粉丝"));
temp.Click();
Console.Read();
}
示例4: Main
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
int idInicio = 30000;
int idFinal = 22000;
int contador = 1;
String url = "";
driver.Navigate().GoToUrl(url + idInicio);
driver.Manage().Window.Maximize();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"e:\AllStudents.csv", true))
{
while (idInicio > idFinal)
{
driver.Navigate().GoToUrl(url + idInicio);
IWebElement nome = driver.FindElement(By.Id("txtNome"));
IWebElement email = driver.FindElement(By.Id("txtmail_maior"));
if (email.GetAttribute("value").ToString() != "")
{
Console.WriteLine(contador + " - " + idInicio.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString());
file.WriteLine(contador + ";" + idInicio.ToString() + ";" + email.GetAttribute("value").ToString() +";"+ nome.GetAttribute("value").ToString());
contador++;
}
idInicio--;
}
}
}
示例5: Attack1_Protected
public void Attack1_Protected()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInput.aspx");
IWebElement query = driver.FindElement(By.Name("fullName"));
query.SendKeys("a','2.1'); update students * set gpa = 4.0; --");
query = driver.FindElement(By.Name("GPA"));
query.SendKeys("3");
query = driver.FindElement(By.Name("button"));
query.Click();
System.Threading.Thread.Sleep(5000);
List<LU.ENGI3675.Proj04.App_Code.Students> students =
LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read();
bool allfour = true;
foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students)
{
if (temp.GPA < 4.0) allfour = false;
Debug.Write((string)temp.Name);
Debug.Write(" ");
Debug.WriteLine((double)temp.GPA);
}
Assert.IsFalse(allfour); //if they aren't all 4.0 gpa, then protected against SQL injection
driver.Quit();
}
示例6: WindowProcess_Demo2
public void WindowProcess_Demo2()
{
var articleName = "[小北De编程手记] : Lesson 02 - Selenium For C# 之 核心对象";
_output.WriteLine("Step 01 : 启动浏览器并打开Lesson 01 - Selenium For C#");
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://www.cnblogs.com/NorthAlan/p/5155915.html";
_output.WriteLine("Step 02 : 点击链接打开新页面。");
var lnkArticle02 = driver.FindElement(By.LinkText(articleName));
lnkArticle02.Click();
_output.WriteLine("Step 03 : 根据标题获取新页面的句柄。");
var oldWinHandle = driver.CurrentWindowHandle;
foreach (var winHandle in driver.WindowHandles)
{
driver.SwitchTo().Window(winHandle);
if (driver.Title.Contains(articleName))
{
break;
}
}
_output.WriteLine("Step 04 : 验证新页面标题是否正确。");
var articleTitle = driver.FindElement(By.Id("cb_post_title_url"));
Assert.Equal<string>(articleName, articleTitle.Text);
_output.WriteLine("Step 05 : 关闭浏览器。");
driver.Quit();
}
示例7: Attack2_NonProtected
public void Attack2_NonProtected()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost/LU.ENGI3675.Project04/StudentInputUNSAFE.aspx");
IWebElement query = driver.FindElement(By.Name("fullNameUS"));
query.SendKeys("a','2.1'); update students * set gpa = 4.0; --");
query = driver.FindElement(By.Name("GPAUS"));
query.SendKeys("0");
query = driver.FindElement(By.Name("button"));
query.Click();
System.Threading.Thread.Sleep(1000);
List<LU.ENGI3675.Proj04.App_Code.Students> students =
LU.ENGI3675.Proj04.App_Code.DatabaseAccess.Read();
foreach (LU.ENGI3675.Proj04.App_Code.Students temp in students)
{
Assert.IsTrue((double)temp.GPA == 4); //if any of them aren't 4.0, injection failed
Debug.Write((string)temp.Name);
Debug.Write(" ");
Debug.WriteLine((double)temp.GPA);
}
driver.Quit();
}
示例8: Main
static void Main(string[] args)
{
// Compile project
// Copy "index.html" and "lenna.png" into CSFileUpload.exe directory (bin\Debug\)
// Run and enjoy!
// создаём объект WebDriver для браузера FireFox
var driver = new FirefoxDriver();
// открываем страницу с формой загрузки файла
var fileUri = GetUriFromPath(Path.Combine(Environment.CurrentDirectory, "index.html"));
driver.Url = fileUri;
// находим элемент <input type="file">
var txtFileUpload = driver.FindElement(By.Id("file"));
// заполняем элемент путём до загружаемого файла
var sourceFile = Path.Combine(Environment.CurrentDirectory, "lenna.png");
txtFileUpload.SendKeys(sourceFile);
// находим элемент <input type="submit">
var btnSubmit = driver.FindElement(By.Id("submit"));
// нажимаем на элемент (отправляем форму)
btnSubmit.Click();
// закрываем браузер
driver.Quit();
}
示例9: Main
static void Main(string[] args)
{
IWebDriver driver = new FirefoxDriver();
const int idInicio = 0;
const int idFim = 1000;
int id = idInicio;
String url = "http://fcv.matheusacademico.com.br/Aluno/frmAlunoAlteracao.asp?id=";
driver.Navigate().GoToUrl(url + id);
driver.Manage().Window.Maximize();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\AllStudents1.txt", true))
{
while (id < idFim)
{
driver.Navigate().GoToUrl(url + id);
IWebElement nome = driver.FindElement(By.Id("txtNome"));
IWebElement email = driver.FindElement(By.Id("txtmail_maior"));
if (nome.GetAttribute("value").ToString() != "")
file.WriteLine(id.ToString() + " - " + nome.GetAttribute("value").ToString() + " - " + email.GetAttribute("value").ToString());
id++;
}
}
}
示例10: TestMensagemAlertaNenhumSelecionado
public void TestMensagemAlertaNenhumSelecionado()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(SITE_URL);
driver.FindElement(By.Id("btnSolucionar")).Click();
Assert.IsTrue(driver.FindElement(By.Id("divErrorMessage")).Displayed);
driver.Quit();
}
示例11: CreateBugTest
public void CreateBugTest()
{
IWebDriver driver = new FirefoxDriver();
string baseURL = "http://ifdefined.com/btnet/bugs.aspx";
StringBuilder verificationErrors = new StringBuilder();
driver.Navigate().GoToUrl(baseURL);
try
{
Assert.AreEqual("BugTracker.NET - bugs", driver.Title);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.XPath("//div[contains(@class, 'align')]/table/tbody/tr/td/a")).Click();
try
{
Assert.AreEqual("BugTracker.NET - Create Bug", driver.Title);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
try
{
Assert.AreEqual("Project:", driver.FindElement(By.XPath("//span[conatins(@id, 'project_label')]")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
// ERROR: Caught exception [ReferenceError: selectLocator is not defined]
driver.FindElement(By.CssSelector("option[value=\"3\"]")).Click();
try
{
Assert.AreEqual("[no project] DemoProject HasCustomFieldsProject HasDifferentPermissionsProject", driver.FindElement(By.Id("project")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
try
{
Assert.AreEqual("Project-specific", driver.FindElement(By.Id("label_pcd1")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.Quit();
}
示例12: MagentoIncorrectUser
public void MagentoIncorrectUser()
{
IWebDriver driver = new FirefoxDriver();
string baseURL = "http://demo.nostresscommerce.cz/";
StringBuilder verificationErrors = new StringBuilder();
driver.Navigate().GoToUrl(baseURL);
driver.FindElement(By.XPath("//*[contains(@class, 'links')]/li/a")).Click();
driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).Clear();
driver.FindElement(By.XPath("//input[contains(@id, 'email')]")).SendKeys("[email protected]");
driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).Clear();
driver.FindElement(By.XPath("//input[contains(@id, 'pass')]")).SendKeys("123456");
driver.FindElement(By.Id("send2")).Click();
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("Login or Create an Account" == driver.FindElement(By.CssSelector("h1")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("Login or Create an Account", driver.FindElement(By.CssSelector("h1")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("Invalid login or password." == driver.FindElement(By.CssSelector("li > span")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("Invalid login or password.", driver.FindElement(By.CssSelector("li > span")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.Quit();
}
示例13: Add_Tweet_FindNewTweetInNewsfeed
public void Add_Tweet_FindNewTweetInNewsfeed()
{
firefox = new FirefoxDriver();
firefox.Navigate().GoToUrl("http://localhost:57336/");
//firefox.FindElement(By.Id("register")).Click();
firefox.FindElement(By.Id("login")).Click();
//register page
//firefox.FindElement(By.Id("inputFirstName")).SendKeys("testFirstName");
//firefox.FindElement(By.Id("inputLastName")).SendKeys("testLastName");
//firefox.FindElement(By.Id("inputEmail")).SendKeys("[email protected]");
//firefox.FindElement(By.Id("inputPassword")).SendKeys("123");
//firefox.FindElement(By.Id("submit")).Click();
//firefox.FindElement(By.Id("login")).Click();
//log in page
firefox.FindElement(By.Id("inputEmail")).SendKeys("[email protected]");
firefox.FindElement(By.Id("inputPassword")).SendKeys("123");
firefox.FindElement(By.Id("login")).Click();
firefox.FindElement(By.Name("Body")).Click();
firefox.FindElement(By.Name("Body")).SendKeys("test Tweet");
firefox.FindElement(By.Id("tweetbutton")).Click();
firefox.FindElement(By.Id("home")).Click();
string tweetMessage = firefox.FindElement(By.TagName("h5")).Text;
Assert.IsTrue(tweetMessage == "test Tweet");
}
示例14: Should_display_asterisk_against_missing_user_name
public void Should_display_asterisk_against_missing_user_name()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://localhost:1392/");
driver.FindElement(By.Id("login_LoginButton")).Click();
var missing = driver.FindElement(By.Id("login_UserNameRequired"));
Assert.IsTrue(missing.Displayed);
driver.Quit();
}
示例15: HackathonTest
public void HackathonTest()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://testerzy.pl");
driver.FindElement(By.Id("mod-search-searchword")).SendKeys("hackathon dev qa");
driver.FindElement(By.ClassName("button")).Click();
Assert.True(driver.FindElement(By.ClassName("result-title")).Text.Contains("Hackathon"));
driver.Quit();
}