本文整理汇总了C#中OpenQA.Selenium.Remote.RemoteWebDriver.FindElement方法的典型用法代码示例。如果您正苦于以下问题:C# RemoteWebDriver.FindElement方法的具体用法?C# RemoteWebDriver.FindElement怎么用?C# RemoteWebDriver.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Remote.RemoteWebDriver
的用法示例。
在下文中一共展示了RemoteWebDriver.FindElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
public static IWebDriver Authenticate()
{
string email = "[email protected]";
IWebDriver 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"));
//webDriver.Quit();
if (elem.Text == "Welcome Admin Development")
{
return webDriver;
}
return null;
}
示例2: DeleteItem
protected void DeleteItem(RemoteWebDriver browser)
{
IWebElement link = browser.FindElement(By.Id("blAHrefLink0"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("DesktopDeleteButton"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
}
示例3: Search
protected void Search(RemoteWebDriver browser)
{
browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
System.Threading.Thread.Sleep(_testStepInterval);
IWebElement link = browser.FindElement(By.Id("searchButtonSubmit"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("CancelSearchResultDisplay"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("searchButtonSubmit"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("ProcessEdit0"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("DesktopDeleteButton"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
browser.FindElement(By.Id("SearchTerm")).SendKeys("drive");
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("searchButtonSubmit"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("ProcessEdit0"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("DesktopEditButton"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
browser.FindElement(By.Id("BIItemName")).SendKeys(" edited item value");
System.Threading.Thread.Sleep(_testStepInterval);
IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
SelectElement selectElement = new SelectElement(rankingItemSelect);
selectElement.SelectByText("Warm");
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("EditBIButtonSubmit"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
}
示例4: setup
//private static ISelenium selenium;
public static void setup()
{
IWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4444/wd/hub"),DesiredCapabilities.HtmlUnit());
//driver = new FirefoxDriver();
Selenium.WebDriverBackedSelenium s = new Selenium.WebDriverBackedSelenium(driver, @"http://site4.way2sms.com/content/index.html");
s.Start();
driver.Navigate().GoToUrl("http://site4.way2sms.com/content/index.html");
WaitForLinkTextPresent(driver, "► click here to go to way2sms.com", 40);
driver.FindElement(By.Id("username")).SendKeys("9916089888");
driver.FindElement(By.Id("password")).SendKeys("suprwolf");
driver.FindElement(By.Id("button")).Click();
if (WaitIdPresent(driver, "quickclose1",40000))
{
driver.FindElement(By.Id("quickclose1")).Click();
}
driver.FindElement(By.Id("quicksms")).Click();
driver.SwitchTo().Frame("frame");
s.WaitForPageToLoad("30000");
driver.FindElement(By.Id("MobNo")).SendKeys("9916089888");
WaitIdPresent(driver, "textArea", 400);
driver.FindElement(By.Id("textArea")).SendKeys("test");
driver.FindElement(By.Id("Send")).Submit();
driver.FindElement(By.LinkText("Logout")).Clear();
}
示例5: SignInAsAdmin
/// <summary>
/// Log a user into the website as an administrator
/// </summary>
/// <param name="driver"></param>
protected void SignInAsAdmin(RemoteWebDriver driver)
{
//Notice navigation is slightly different than the Java version
//This is because 'get' is a keyword in C#
driver.Navigate().GoToUrl(BaseUrl + "/User/SignIn");
// Find the text input element by its name
driver.FindElement(By.Name("Email")).SendKeys(_adminEmail);
driver.FindElement(By.Name("Password")).SendKeys(_adminPass);
driver.FindElement(By.CssSelector("button.btn-primary")).Click();
driver.WaitFor(u => u.Url.Contains("Manage"));
}
示例6: FindPrice
public void FindPrice()
{
IWebDriver driver_ = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
driver_.Navigate().GoToUrl("http://www.momoshop.com.tw");
driver_.FindElement(By.CssSelector("#keyword")).SendKeys(this.SearchKeyWord_);
driver_.FindElement(By.CssSelector(".inputbtn")).Click();
Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();
try
{
if (driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count == 0)
{
ReadProductDetail(driver_.Url, ref info);
}
else
{
var PageCount = driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count;
for (var CurrentPage = 1; CurrentPage <= PageCount;)
{
List<IWebElement> products = driver_.FindElements(By.XPath("//*[@id=\"chessboard\"]/li/a")).ToList();
foreach (var product in products)
{
ReadProductDetail(product.GetAttribute("href"), ref info);
}
//Last Page
if (CurrentPage == PageCount)
{
break;
}
//Next Page
++CurrentPage;
driver_.FindElement(By.XPath(string.Format("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li[{0}]/a", CurrentPage))).Click();
}
}
}
catch (NoSuchElementException)
{
}
this.ProductDetail_.Add("momo", info);
driver_.Quit();
if (LocalDriver_ != null)
{
LocalDriver_.Quit();
}
return;
}
示例7: EditItem
protected void EditItem(RemoteWebDriver browser)
{
IWebElement link = browser.FindElement(By.Id("btnEdit0"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
browser.FindElement(By.Id("BIItemName")).SendKeys("edited item value");
System.Threading.Thread.Sleep(_testStepInterval);
IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
SelectElement selectElement = new SelectElement(rankingItemSelect);
selectElement.SelectByText("Warm");
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("EditBIButtonSubmit"));
link.Click();
}
示例8: SaveAndRecordSubmittedTags
public static string[] SaveAndRecordSubmittedTags( RemoteWebDriver driver )
{
// Save
driver.FindElement( By.Id( "save_tags" ) ).Click();
// Stash the values we entered
var tagsAsSubmitted = driver.FindElements( By.CssSelector( "input.tag_name" ) ).Select( tagNameEl => tagNameEl.GetAttribute( "value" ).Trim() ).ToArray();
// Wait for the success report
new WebDriverWait( driver, TimeSpan.FromSeconds( 10 ) ).Until( d =>
{
var messagesElement = driver.FindElement( By.Id( "messages" ) );
return messagesElement.Displayed && -1 != messagesElement.Text.IndexOf( "saved successfully", StringComparison.InvariantCultureIgnoreCase );
} );
return tagsAsSubmitted;
}
示例9: Selenium_Server_Test
public void Selenium_Server_Test()
{
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.Firefox());
driver.Url = "http://www.google.com";
var searchBox = driver.FindElement(By.Id("lst-ib"));
searchBox.SendKeys("Lotus flower");
searchBox.SendKeys(Keys.Enter);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
var imagetext = driver.FindElement(By.LinkText("Kuvahaku"));
Assert.That(imagetext.Text, Is.EqualTo("Kuvahaku"));
imagetext.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); //avoid error on no such element
var imagelistId = driver.FindElement(By.Id("rg_s"));
var fouthdivclass = imagelistId.FindElements(By.CssSelector("[class='rg_di rg_el ivg-i']"))[1].FindElement(By.TagName("a"));
fouthdivclass.Click();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
var ImageLink = driver.FindElement(By.LinkText("Näytä kuva"));
ImageLink.Click();
}
示例10: FindPrice
public void FindPrice()
{
IWebDriver driver = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
driver.Navigate().GoToUrl("http://www.pcstore.com.tw/");
Thread.Sleep(1000);
//#id_search_word
driver.FindElement(By.CssSelector("#id_search_word")).SendKeys(this.SearchKeyWord_);
driver.FindElement(By.XPath("//*[@id=\"top-search\"]/img")).Click();
Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();
for (; ; )
{
List<IWebElement> ProductList = driver.FindElements(By.XPath("//*[@id=\"keyad-pro-right3\"]/div[1]/a")).ToList();
foreach (var product in ProductList)
{
ReadProductDetail(product.GetAttribute("href"), ref info);
}
try
{
driver.FindElement(By.XPath("//*[@id=\"container\"]/div[10]/table[1]/tbody/tr/td[5]/a")).Click();
Thread.Sleep(1000);
}
catch (System.Exception)
{
break;
}
}
this.ProductDetail_.Add("PcHome", info);
if (LocalDriver_ != null)
{
LocalDriver_.Quit();
}
driver.Quit();
return;
}
示例11: GivenThatINavigateToABlogPostThatContainsAnImage
public void GivenThatINavigateToABlogPostThatContainsAnImage()
{
var driver = new RemoteWebDriver(new Uri("http://localhost"), DesiredCapabilities.HtmlUnitWithJavaScript());
// Find the text input element by its name
driver.Navigate();
// Enter something to search for
IWebElement element = driver.FindElement(By.Id(""));
// Now submit the form. WebDriver will find the form for us from the element
//element.S
}
示例12: AddItemFromEditMenu
protected void AddItemFromEditMenu(RemoteWebDriver browser)
{
IWebElement link = browser.FindElement(By.Id("blAHrefLink0"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("DesktopAddButton"));
link.Click();
System.Threading.Thread.Sleep(_testStepInterval);
browser.FindElement(By.Id("BIItemName")).SendKeys("Bucket List Item 2");
System.Threading.Thread.Sleep(_testStepInterval);
IWebElement rankingItemSelect = browser.FindElement(By.Name("rankingItemSelect"));
SelectElement selectElement = new SelectElement(rankingItemSelect);
selectElement.SelectByText("Cool");
System.Threading.Thread.Sleep(_testStepInterval);
link = browser.FindElement(By.Id("AddBIButtonSubmit"));
link.Click();
}
示例13: CreateCustomerShouldSucceed
public static void CreateCustomerShouldSucceed( RemoteWebDriver driver, AuthenticatingNavigator navigator )
{
using ( driver.FinallyQuitGuard() ) // TODO improve this using http://xunit.codeplex.com/workitem/9798 ( WAS: http://xunit.codeplex.com/discussions/362097 )
{
navigator.NavigateWithAuthenticate( driver, "Sp.Web.Consume/Customer/Create" );
WebDriverWait wait = new WebDriverWait( driver, TimeSpan.FromSeconds( 5 ) );
wait.Until( d => d.FindElement( By.Id( "create-view" ) ) );
IWebElement nameElement = driver.FindElement( By.Id( "name" ) );
string anonymousCustomerName = "anonymousName" + Guid.NewGuid();
nameElement.SendKeys( anonymousCustomerName );
IWebElement externalIdElement = driver.FindElement( By.Id( "externalId" ) );
externalIdElement.SendKeys( "anonymousExternalId" );
IWebElement createButton = driver.FindElement( By.Id( "add-customer" ) );
createButton.Click();
wait.Until( d => d
.FindElement( By.Id( "messages" ) )
.Text.Contains( "Customer created successfully" ) );
}
}
示例14: Main
static void Main(string[] args)
{
DesiredCapabilities capability = null;
IWebDriver driver = null;
for (int i = 1; i < 4; i++)
{
switch (i)
{
case 1:
capability = DesiredCapabilities.Firefox();
capability.SetCapability("BrowserName", "firefox");
break;
case 2:
capability = DesiredCapabilities.Chrome();
capability.SetCapability("BrowserName", "chrome");
break;
case 3:
capability = DesiredCapabilities.InternetExplorer();
capability.SetCapability("BrowserName", "internet explorer");
break;
default:
return;
}
driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
driver.Manage().Window.Maximize();
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10));
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
driver.Navigate().GoToUrl("http://www.baidu.com");
IWebElement searchBox = driver.FindElement(By.Id("kw"));
IWebElement searchButton = driver.FindElement(By.Id("su"));
searchBox.SendKeys("Shinetech");
searchButton.Click();
driver.Dispose();
}
}
示例15: Should_be_able_to_read_text_from_label_when_content_is_more_than_just_text
public void Should_be_able_to_read_text_from_label_when_content_is_more_than_just_text()
{
var pagePath = Path.Combine(Environment.CurrentDirectory, "markup.html");
driver = new FirefoxDriver();
driver.Navigate().GoToUrl(pagePath);
var container = driver.FindElement(By.ClassName("some-class"));
var labels = container.FindElements(By.TagName("label"));
// This works:
Assert.That(labels[0].GetAttribute("class"), Is.EqualTo("some-other-class"));
// But not this:
Assert.That(labels[0].Text, Is.EqualTo("Alla kommuner"));
}