本文整理汇总了C#中IWebDriver.FindElements方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.FindElements方法的具体用法?C# IWebDriver.FindElements怎么用?C# IWebDriver.FindElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebDriver
的用法示例。
在下文中一共展示了IWebDriver.FindElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindElementsWithTimeoutWait
/// <summary>
/// Finds the elements with timeout wait.
/// </summary>
/// <param name="driver">The driver.</param>
/// <param name="by">The by.</param>
/// <returns></returns>
public static ReadOnlyCollection<IWebElement> FindElementsWithTimeoutWait(IWebDriver driver, By by)
{
Exception ex = null;
ReadOnlyCollection<IWebElement> e = null;
long elapsedTime = 0;
while (elapsedTime < TimeOut)
{
try
{
elapsedTime++;
StandardSleep(1);
e = driver.FindElements(by);
break;
}
catch (NoSuchElementException nse)
{
if (e == null)
throw ex;
}
}
if (e == null)
throw ex;
return e;
}
示例2: 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;
}
}
示例3: Execute
public CommandResult Execute(IWebDriver driver, CommandDesc command)
{
try
{
var result = new CommandResult { Command = command };
var timeout = GetTimeout(command);
var complexSelector = WebDriverExtensions.GetContainsSelector(command.Selector);
var by = WebDriverExtensions.GetBy(complexSelector.SimpleSelector);
var elements = driver.FindElements(by);
if (elements.Any())
driver.WaitForNotElement(by, timeout.GetValueOrDefault(WebDriverExtensions.DEFAULT_TIMEOUT));
elements = driver.FindElements(by);
var count = elements.Count();
if (count > 0)
throw new Exception("Element was found.");
return result;
}
catch (Exception ex)
{
return new CommandResult
{
Command = command,
HasError = true,
Comments = ex.Message
};
}
}
示例4: 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();
}
示例5: ClickFor
/// <summary>
/// forが含まれているタグを検索しクリックする
/// </summary>
/// <param name="webDriver">webDriver</param>
/// <param name="name">name</param>
public void ClickFor(IWebDriver webDriver, string contain)
{
try
{
IList<IWebElement> tag_input = webDriver.FindElements(By.XPath(string.Format("//*[contains(@for,'{0}')]", contain)));
capche.SaveCapche(webDriver);
foreach (IWebElement tag in tag_input)
{
if (tag.Displayed)
{
tag.Click();
return;
}
}
throw new OriginalException(string.Format("contain:{0}, Not Found", contain));
}
catch (Exception ex)
{
throw new OriginalException(string.Format("containUrl:{0}, ClickFor, ErrorMessage:{1}", contain, ex.Message));
}
finally
{
capche.SaveCapche(webDriver);
}
}
示例6: TheXTest
public void TheXTest()
{
driver = new FirefoxDriver();
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
Login u = new Login(driver);
string login1 = "guest";
u.get().login(login1, login1).click();//вход на сайт
driver.FindElement(By.Id("sovzond_widget_SimpleButton_104")).Click();
Thread.Sleep(5000);
IWebElement element = driver.FindElement(By.Id("sovzond_widget_SimpleButton_0"));
var builder = new Actions(driver);
builder.Click(element).Perform();
IList<IWebElement> el = driver.FindElements(By.ClassName("svzLayerManagerItem"));
for (int n = 0; n < el.Count; n++)
{
if (el[0].Text != "Google") Assert.Fail("не найден Google");
if (el[4].Text != "Росреестр") Assert.Fail("не найден Росреестр");
if (el[5].Text != "OpenStreetMap") Assert.Fail("не найден OpenStreetMap");
if (el[6].Text != "Топооснова") Assert.Fail("не найден Топооснова");
}
IWebElement element1 = driver.FindElement(By.Id("dijit_form_RadioButton_3"));
builder.Click(element1).Perform();
Thread.Sleep(5000);
string h= (string)js.ExecuteScript("return window.portal.stdmap.map.baseLayer.div.id.toString()");
}
示例7: logout
public static void logout(IWebDriver driver)
{
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(0));
System.Collections.ObjectModel.ReadOnlyCollection<IWebElement> e = driver.FindElements(By.LinkText("Logout"));
if (e.Count > 0) e.First().Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Config.implicitTimeout));
}
示例8: HandleElement
public void HandleElement(IWebElement el, IWebDriver browser, string[] parameters)
{
var targetvalue = parameters[2];
el.Click();
IList<IWebElement> comboItems = browser.FindElements(By.CssSelector(".x-boundlist .x-boundlist-item"));
comboItems.First(item => item.Text.Trim() == targetvalue).Click();
}
示例9: GetLinks
public List<IWebElement> GetLinks(IWebDriver driver)
{
if (_pageLinks == null)
{
_pageLinks = driver.FindElements(By.TagName("a")).ToList();
}
return _pageLinks;
}
示例10: CheckElementExists
public static bool CheckElementExists(string CssSelector, IWebDriver d)
{
IList<IWebElement> eleList = d.FindElements(By.CssSelector(CssSelector));
if (eleList.Count > 0)
{
return true;
}
return false;
}
示例11: Culture
public void Culture(IWebDriver driver, Datarow datarow)
{
try
{
driver.FindElement(By.LinkText("MoShop")).Click();
driver.FindElement(By.CssSelector("#IndexMenuLeaf3 > a")).Click();
driver.FindElement(By.LinkText("testshop")).Click();
driver.FindElement(By.LinkText("Shop")).Click();
try
{
driver.FindElement(By.CssSelector("h3.collapsible.collapsed")).Click();
driver.FindElement(By.CssSelector("h3.collapsible.collapsed")).Click();
}
catch (Exception ex)
{
ex.ToString();
}
driver.FindElement(By.Id("CustomDomainName")).SendKeys("m.testshop.com");
driver.FindElement(By.CssSelector("input.button")).Click();
new SelectElement(driver.FindElement(By.Id("DefaultCultureSelected"))).SelectByText(
"Telugu (India) - ₹ [te-IN]");
driver.FindElement(By.CssSelector("input.button")).Click();
decimal count = driver.FindElements(By.XPath("//div[@id='CataloguesControl']/div/table/tbody/tr")).Count;
for (var i = 1; i <= count; i++)
{
var name = GetValue(driver,
By.XPath("//div[@id='CataloguesControl']/div/table/tbody/tr[" + i +
"]/td/input"), 30);
if (name != "Default") continue;
driver.FindElement(By.XPath("//*[@id='CataloguesControl']/div/table/tbody/tr[" + i + "]/th[2]/a"))
.Click();
driver.FindElement(By.CssSelector("input.button")).Click();
new SelectElement(driver.FindElement(By.Id("Culture_Value"))).SelectByText(
"Telugu (India) - ₹ [te-IN]");
driver.FindElement(By.CssSelector("input.button")).Click();
break;
}
//Inserting Category Images.
new CategoryImages().Images(driver, datarow);
driver.Navigate().GoToUrl("http://m.testshop.com");
var url = driver.Url;
datarow.Newrow("Customa Domain Name", "http://m.testshop.com/", url,
url == "http://m.testshop.com" ? "PASS" : "FAIL", driver);
}
catch (Exception ex)
{
var e = ex.ToString();
datarow.Newrow("Exception", "Exception Not Exopected", e, "PASS", driver);
}
}
示例12: GetElements
private static IWebElement GetElements(IWebDriver driver, string query, int index)
{
var elements = driver.FindElements(By.XPath(query));
if (!elements.Any())
{
throw new Exception(string.Format("No elements returned with query {0} looking for index {1}", query, index));
}
return elements[index];
}
示例13: Page_Chrome_ShouldContain_DisplayFor_FirstName
public void Page_Chrome_ShouldContain_DisplayFor_FirstName()
{
//Arrange
_webDriver = WebDriver.InitializeChrome();
_webDriver.Navigate().GoToUrl("http://localhost/TestDrivingMVC.Web/Customer/Index/1");
//Act
IWebElement result = _webDriver.FindElements(By.TagName("label")).FirstOrDefault(x => x.Text == "First Name");
//Assert
result.Should().NotBeNull();
}
示例14: FindElements
private static IEnumerable<IWebElement> FindElements(IWebDriver driver, By selector)
{
try
{
return driver.FindElements(selector);
}
catch (NoSuchElementException)
{
return null;
}
}
示例15: FindElements
public static ReadOnlyCollection<IWebElement> FindElements(IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(currentDriver => (currentDriver.FindElements(by).Count > 0) ? currentDriver.FindElements(by) : null);
}
else
{
return driver.FindElements(by);
}
}