本文整理汇总了C#中IWebDriver.FindElement方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.FindElement方法的具体用法?C# IWebDriver.FindElement怎么用?C# IWebDriver.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebDriver
的用法示例。
在下文中一共展示了IWebDriver.FindElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectDropDown
//Selecting a drop down control
public static void SelectDropDown(IWebDriver driver, string element, string value, string elementtype)
{
if (elementtype == "Id")
new SelectElement(driver.FindElement(By.Id(element))).SelectByText(value);
if (elementtype == "Name")
new SelectElement(driver.FindElement(By.Name(element))).SelectByText(value);
}
示例2: EnterText
public static void EnterText(IWebDriver driver, string element, string value, string elementtype)
{
if (elementtype == "Id")
driver.FindElement(By.Id(element)).SendKeys(value);
if (elementtype == "Name")
driver.FindElement(By.Name(element)).SendKeys(value);
}
示例3: FillOutLoginForm
public static bool FillOutLoginForm(IWebDriver driver, string username, string password, IWebElement submitButton = null, IWebElement usernameField = null, IWebElement passwordField = null)
{
try
{
if (usernameField == null && driver.FindElements(By.XPath(txtUsernameXPath)).Count > 0)
usernameField = driver.FindElement(By.XPath(txtUsernameXPath));
if (passwordField == null && driver.FindElements(By.XPath(txtPasswordXPath)).Count > 0)
passwordField = driver.FindElement(By.XPath(txtPasswordXPath));
if (submitButton == null && driver.FindElements(By.XPath(btnSubmitXPath)).Count > 0)
submitButton = driver.FindElement(By.XPath(btnSubmitXPath));
if (usernameField != null && passwordField != null && submitButton != null)
{
usernameField.SendKeys(username);
passwordField.SendKeys(password);
submitButton.SendKeys(Keys.Enter);
return true;
}
return false;
}
catch (IllegalLocatorException e)
{
return false;
}
}
示例4: GoogleSearch
public GoogleSearch(IWebDriver driver, string p1, string p2)
{
try
{
driver.Navigate().GoToUrl("http://www.google.pt");
driver.FindElement(By.Name("q")).SendKeys(p1);
Logger.Out("Driver title before send keys enter =" + driver.Title);
//get the suggestions box from google
Logger.Out(DateTime.Now.ToString());
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
wait.Until((d) => { return d.FindElement(By.ClassName("gssb_e")).Displayed; });
IWebElement resultsDiv = driver.FindElement(By.ClassName("gssb_e"));
Logger.Out(DateTime.Now.ToString());
//// If results have been returned, the results are displayed in a drop down.
if (resultsDiv.Displayed)
{
Logger.Out("Suggestions appeared");
}
else
throw new Exception("No suggestions");
driver.FindElement(By.Name("q")).SendKeys(Keys.Enter);
Logger.Out("before wait"+driver.Title);
wait.Until((d) => { return d.Title.StartsWith("banana"); });
//Check that the Title is what we are expecting
Assert.AreEqual(p1+" - Pesquisa do Google", driver.Title);
Logger.Out("after wait & assert- "+driver.Title);
}
catch (Exception ex)
{
throw ex;
}
}
示例5: Case001_Login
public void Case001_Login()
{
// InternetExplorerOptions options = new InternetExplorerOptions();
// options.IgnoreZoomLevel = true;
driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://sheltered-stream-7018.herokuapp.com/");
IWebElement testLogin = driver.FindElement(By.ClassName("login_button"));
testLogin.Click();
IWebElement enterLogin = driver.FindElement(By.Id("username_or_email"));
enterLogin.SendKeys("azimuth_user_1");
enterLogin = driver.FindElement(By.Id("password"));
enterLogin.SendKeys("whiskey");
IWebElement testAuthorize = driver.FindElement(By.Id("allow"));
testAuthorize.Click();
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(4));
IWebElement findH2 = driver.FindElement(By.TagName("h2"));
string doesTitleExist = findH2.Text;
System.Console.WriteLine(doesTitleExist);
Assert.AreEqual(doesTitleExist,"Profile");
}
示例6: PopulateProjectNameWithSpecialChar
public void PopulateProjectNameWithSpecialChar(IWebDriver driverInstance)
{
IWebElement input = driverInstance.FindElement(NgBy.Input("ProjectWizardController.project.name"));
input.Clear();
input.SendKeys("##TEST##");
driverInstance.FindElement(By.Id("txtDescription")).Click();
}
示例7: PasswordlessAuthentication
public void PasswordlessAuthentication()
{
string email = "[email protected]";
_webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());
_webDriver.Manage().Window.Maximize();
_webDriver.Navigate().GoToUrl("http://dev.icms/Account/Login");
//Enter email address on login page
IWebElement emailLogin = _webDriver.FindElement(By.Id("Email"));
emailLogin.Clear();
emailLogin.SendKeys(email);
IWebElement authenticateButton = _webDriver.FindElement(By.Id("requestauth"));
authenticateButton.Click();
//this should have sent me an email
//Let's pretend we got the email and check the server for the authtoken and plug it into the URL
string token = HttpUtility.UrlEncode(TestUtilities.AuthenticationUtil.GetAuthToken(email));
string goToUrl = string.Format("http://dev.icms/account/authorize/?authtoken={0}&email={1}&returnUrl=%2f", token, email);
_webDriver.Quit();
_webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());
_webDriver.Navigate().GoToUrl(goToUrl);
//Check DOM to see if we are logged in
IWebElement elem = _webDriver.FindElement(By.CssSelector("h1"));
Assert.IsTrue(elem.Text == "Welcome Admin Development");
}
示例8: Cookie
public void Cookie(IWebDriver driver, Datarow datrow)
{
try
{
//cookie Disclosure
IsElementPresent(driver, By.CssSelector("div.cookieDisclosure"));
var disclosuretext = driver.FindElement(By.CssSelector("div.cookieDisclosure")).Text;
datrow.Newrow("Diclosure Text is Presnt",
"This site uses cookies. Some of the cookies we use are essential for parts of the site to operate and have already been set.",
disclosuretext, disclosuretext ==
"This site uses cookies. Some of the cookies we use are essential for parts of the site to operate and have already been set."
? "PASS"
: "FAIL");
if (IsElementPresent(driver, By.Id("epdsubmit")))
{
driver.FindElement(By.Id("epdsubmit")).Click();
datrow.Newrow("Validating 'OK' Button in cookie disclosure ", "OK button is present",
"OK button is present", "PASS");
}
else
{
datrow.Newrow("Validating 'OK' Button in cookie disclosure ", "OK button is present",
"OK button is not present", "FAIL");
}
}
catch (Exception ex)
{
var e = ex.ToString();
datrow.Newrow("Exception Not Expceted", "Not Expected", e, "FAIL");
}
}
示例9: AssetSelection
private static void AssetSelection(IWebDriver driver)
{
for (var n = 0; n <= 1; n++)
{
driver.FindElement(By.CssSelector("img.img-responsive.center-block")).Click();
driver.FindElement(By.Id("s2id_autogen1")).Click();
var groups = new SelectElement(driver.FindElement(By.Id("groups")));
groups.SelectByIndex(n);
var assetType = groups.SelectedOption.Text;
driver.FindElement(By.CssSelector("button.btn.gradient")).Click(); //click search
//Groups dropdown
IList<IWebElement> details = driver.FindElements(By.LinkText("Details"));
Console.WriteLine("There are {0} {1} ", details.Count(), assetType);
NavigateGroups(driver, details);
// driver.FindElement(By.CssSelector("img.img-responsive.center-block")).Click();
// driver.FindElement(By.CssSelector("a.select2-search-choice-close")).Click(); //clear
}
//Console.ReadKey();
}
示例10: ExecuteScript
private static void ExecuteScript(IWebDriver wd)
{
try
{
//wd.Manage().Window.Maximize();
//Console.WriteLine("Browser Maximizado");
wd.Navigate().GoToUrl("http://www.minhaseconomias.com.br");
Console.WriteLine("Acessado o Site Minhas Economias");
wd.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
wd.FindElement(By.ClassName("login")).Click();
wd.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
Console.WriteLine("Clicado no Botão de 'Entrar'");
wd.FindElement(By.Id("email")).SendKeys("[email protected]");
Console.WriteLine("Digitado o Login (E-mail)");
wd.FindElement(By.Id("senha")).SendKeys("[email protected]");
Console.WriteLine("Digitada a Senha");
wd.FindElement(By.Id("login")).FindElement(By.Name("OK")).Click();
Console.WriteLine("Clicado no botão 'Entrar'");
}
finally
{
wd.Close();
}
}
示例11: Dsecure
public void Dsecure(IWebDriver driver)
{
var frameElement = driver.FindElement(By.TagName("iframe"));
driver.SwitchTo().Frame(frameElement);
driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
Thread.Sleep(0x1388);
Thread.Sleep(0x1f40);
var location = driver.Url;
if (location.Contains("3DSecureState=Success"))
{
_datarow.Newrow("3D secure", location, "3DSecureState=Success", "PASS", driver);
if (IsElementPresent(driver, By.LinkText("start again")))
{
driver.FindElement(By.LinkText("start again")).Click();
}
else
{
driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
}
}
else
{
_datarow.Newrow("3D secure", location, "3D secure Declined", "FAIL", driver);
if (IsElementPresent(driver, By.LinkText("start again")))
{
driver.FindElement(By.LinkText("start again")).Click();
}
else
{
driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
}
}
}
示例12: Dsecure
public void Dsecure(IWebDriver driver)
{
if (IsElementPresent(driver, By.TagName("iframe")))
{
var frameElement = driver.FindElement(By.TagName("iframe"));
driver.SwitchTo().Frame(frameElement);
driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
Thread.Sleep(0x1388);
driver.SwitchTo().Alert().Accept();
var location = driver.Url;
if (location.Contains("3DSecureState=Success"))
{
_datarow.Newrow("3D secure", location, "3DSecureState=Success", "PASS", driver);
driver.FindElement(By.LinkText("start again")).Click();
}
else if (location.Contains("State=Declined"))
{
_datarow.Newrow("3D secure", location, "3D secure Declined", "FAIL", driver);
driver.FindElement(By.LinkText("start again")).Click();
}
}
else
{
var actual = driver.Url;
_datarow.Newrow("Checkout", "Server Error", actual, "FAIL", driver);
new Screenshot().Screenshotfailed(driver);
driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
}
}
示例13: ButtonClickTest
private static void ButtonClickTest(IWebDriver driver)
{
driver.Url = "http://www.wikipedia.org";
IWebElement searchInput = driver.FindElement(By.Id("searchInput"));
searchInput.SendKeys("Main Page");
IWebElement searchForm = driver.FindElement(By.Id("search-form"));
searchForm.Submit();
//find the span for 'From today's featured article'
IWebElement todayFeatureArticleBanner = driver.FindElement(By.Id("From_today.27s_featured_article"));
//then go up to find the tr element containing the span
IWebElement todayFeatureArticleBannerRow = todayFeatureArticleBanner.FindElement(By.XPath("../../.."));
//then find its first tr slibing
IWebElement todayFeatureArticleRow = todayFeatureArticleBannerRow.FindElement(By.XPath("following-sibling::tr[1]"));
//then find the first bolded italic link at any level, // is for looping through all children
IWebElement todayFeatureArticleLink = todayFeatureArticleRow.FindElement(By.XPath("//i/b/a"));
Debug.WriteLine(String.Format("Today's Featured Article is \"{0}\", which is listed under the following categories:", todayFeatureArticleLink.Text));
todayFeatureArticleLink.Click();
//find an element with id catlinks
var categoryLinksDiv = driver.FindElement(By.Id("catlinks"));
//find all elements under the element with a div/ul/li path
var categoryLinksLis = categoryLinksDiv.FindElements(By.XPath("div/ul/li"));
foreach (var category in categoryLinksLis)
{
Debug.WriteLine(category.Text);
}
}
示例14: WhereIsMyCheese
public void WhereIsMyCheese(string url)
{
try
{
_driver = Browser.GetFirefoxDriver();
_driver.Navigate().GoToUrl(url);
_driver.FindElement(By.Id("windowOpener")).Click();
_driver.SwitchTo().Window("windowName");
_driver.FindElement(By.Id("CheesyButton")).Click();
_driver.SwitchTo().Alert().Accept();
}
catch (System.Exception ex)
{
Console.WriteLine("An exception occured: " + ex.Message);
Debug.WriteLine("An exception occured: " + ex.Message);
}
finally
{
_driver.Quit();
}
}
示例15: SelectDropDown
//Select from dropdown
public static void SelectDropDown(IWebDriver driver, string element, string value, string elementType)
{
if (elementType == "id")
new SelectElement(driver.FindElement(By.Id(element))).SelectByText(value);
if (elementType == "XPath")
new SelectElement(driver.FindElement(By.XPath(element))).SelectByText(value);
}