本文整理汇总了C#中IWebDriver.Close方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.Close方法的具体用法?C# IWebDriver.Close怎么用?C# IWebDriver.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebDriver
的用法示例。
在下文中一共展示了IWebDriver.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: Login
public bool Login(string login, string password)
{
Driver = new FirefoxDriver();
var lp = new LoginPage2Gis(Driver);
lp.DoLogin(login, password);
// что-то проверяем
//...
Driver.Close();
return true;
}
示例3: Main
static void Main(string[] args)
{
errstring = "";
w("START");
w(" Initialize variables, set up outfiles");
apppath = curdir();
appname = curname();
xlname = appname + ".xls";
xlpath = apppath + "\\" + xlname;
logname = appname + ".log";
mkdir("results");
curpath = "results\\" + dtstring() + "-" + appname;
webfile = appname + ".html";
mkdir(curpath);
webpath = curpath + "\\" + webfile;
logpath = curpath + "\\" + logname;
w(" Fetch variables from the Excel sheet");
openXL(xlpath);
targetURL = getXLParm("targetURL");
uid = getXLParm("uid");
uname = getXLParm("uname");
pid = getXLParm("pid");
pw = getXLParm("pword");
submitid = getXLParm("submitID");
webfile = getXLParm("webfile");
test = getXLParm("test");
webfile = datestring + "-" + webfile;
closeXL();
//w(" Open browser");
//d = new FirefoxDriver();
d = new ChromeDriver();
w(" Navigate to the login screen");
go (targetURL);
w(" Login");
w(" Run the tests - as indicated in the Excel sheet");
exec(test);
//Close and clean up browser stuff
w("Clean up");
d.Close();
d.Quit();
w("END");
//Output results to web page and display it
writeHTML(webpath);
string webspec = apppath + "/" + webpath;
startIE(webspec);
}
示例4: SearchAndNavigateTest
private static void SearchAndNavigateTest(IWebDriver driver)
{
try
{
driver.Navigate().GoToUrl("http://www.bing.com/");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
IWebElement searchInput = driver.FindElement(By.Id("sb_form_q"));
searchInput.SendKeys("aplicacoesweb selenium");
searchInput.SendKeys(Keys.Return);
IWebElement webSiteAnchor = driver.FindElement(By.XPath(("//a[contains(@href,\"aplicacoesweb.blogspot\")]")));
webSiteAnchor.Click();
}
finally
{
driver.Close();
}
}
示例5: closeWindows
public static void closeWindows(IWebDriver driver, string[] titles)
{
try
{
System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
foreach (String window in windowHandles)
{
Console.WriteLine(driver.Title.ToString());
try
{
driver.SwitchTo().Window(window);
}
catch
{
Console.WriteLine("Hang Up");
break;
}
try
{
bool found = false;
foreach (string title in titles)
{
if (driver.Title.Contains(title))
{
found = true;
break;
}
}
if (!found)
{
driver.SwitchTo().Window(window);
driver.Close();
}
}
catch { }
}
}
catch { }
}
示例6: RunTests
public void RunTests()
{
try
{
_driver = Browser.GetFirefoxDriver();
string homepage = "http://google.co.uk";
string searchTerm = "Manual testing is long";
GooglePage googlePage = new GooglePage(_driver);
googlePage.OpenPage(homepage);
googlePage.SearchFor(searchTerm);
googlePage.PageTitle();
googlePage.Close();
}
finally
{
_driver.Close();
}
}
示例7: start
public void start()
{
setTypeChart();
setTeam();
//webDriver = new FirefoxDriver();
webDriver = new ChromeDriver(@"D:\Programming\Pokemon Showdown Bot");
init();
while (running)
{
rocksSet = false;
while (findABattle())
{
Thread.Sleep(50);
}
Debug.WriteLine("Battle found!");
battle();
exitBattle();
}
calculator.exit();
webDriver.Close();
}
示例8: Destroy
//Clean and Destroy drivers and processes
public static void Destroy(IWebDriver driver)
{
try
{
driver.Close();
driver.Quit();
Process[] processes = Process.GetProcessesByName("IEDriverServer");
if (processes.Length > 0)
{
KillProcessByName("iexplore");
KillProcessByName("IEDriverServer");
}
processes = Process.GetProcessesByName("chromedriver");
if (processes.Length > 0)
{
KillProcessByName("chrome");
KillProcessByName("chromedriver");
}
}
catch (Exception) { }
}
示例9: videos
void videos(IWebDriver driver)
{
bool clicked = false;
while (true)
{
try
{
System.Collections.ObjectModel.ReadOnlyCollection<string> MorewindowHandles = driver.WindowHandles;
foreach (String window in MorewindowHandles)
{
try
{
IWebDriver popup = driver.SwitchTo().Window(window);
}
catch { }
try
{
if (driver.Title.Contains("Facebook"))
{
driver.Close();
}
}
catch { }
try
{
driver.SwitchTo().DefaultContent();
Helpers.ByClass(driver, "jw-icon");
try
{
driver.FindElement(By.Id("tvStillTherePopupContinue")).Click();
}
catch { }
if (!clicked)
{
IList<IWebElement> offerButtons = driver.FindElements(By.ClassName("offerButton"));
int counter = 0;
foreach (IWebElement offerButton in offerButtons)
{
if (counter > 1)
{
offerButton.Click();
break;
}
counter++;
}
}
}
catch
{
try
{
driver.FindElement(By.LinkText("Earn Now")).Click();
}
catch { }
}
Helpers.switchFrameByNumber(driver, 0);
try
{
IList<IWebElement> oLinks = driver.FindElements(By.ClassName("singleselectset_radio"));
Random random = new Random();
int rndClick = random.Next(1, oLinks.Count);
Console.WriteLine(rndClick);
int counterClick = 1;
foreach (IWebElement oLink in oLinks)
{
Console.WriteLine(counterClick);
if (counterClick == rndClick)
{
oLink.Click();
}
counterClick++;
}
}
catch { }
try
{
IWebElement dropDownMonth = driver.FindElement(By.Id("dob_month"));
IWebElement dropDownDay = driver.FindElement(By.Id("dob_day"));
IWebElement dropDownYear = driver.FindElement(By.Id("dob_year"));
string[] months = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
Random random = new Random();
int rndMonth = random.Next(0, 11);
Console.WriteLine(rndMonth);
SelectElement clickThis = new SelectElement(dropDownMonth);
clickThis.SelectByText(months[rndMonth]);
Helpers.wait(1000);
int rndDay = random.Next(1, 28);
clickThis = new SelectElement(dropDownDay);
clickThis.SelectByText(rndDay.ToString());
Helpers.wait(1000);
int rndYear = random.Next(1974, 1994);
clickThis = new SelectElement(dropDownYear);
//.........这里部分代码省略.........
示例10: CloseBrowserAndDispose
private static void CloseBrowserAndDispose(IWebDriver driver)
{
driver.Close();
driver.Dispose();
}
示例11: TheCandidateTestChrome
public void TheCandidateTestChrome()
{
Random gen = new Random();
driver = new ChromeDriver(@"C:\Documents and Settings\My Documents\IEWebdriver");
//driver = new FirefoxDriver();
//driver = new InternetExplorerDriver(@"C:\Documents and Settings\My Documents\IEWebdriver");
baseURL = "http://test.telerikacademy.com/";
verificationErrors = new StringBuilder();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
driver.Navigate().GoToUrl("http://test.telerikacademy.com/SoftwareAcademy/Candidate");
driver.FindElement(By.Id("UsernameOrEmail")).Clear();
driver.FindElement(By.Id("UsernameOrEmail")).SendKeys("qaacademy2013");
driver.FindElement(By.Id("Password")).Clear();
driver.FindElement(By.Id("Password")).SendKeys("qastudent");
driver.FindElement(By.CssSelector("input.submit-button")).Click();
driver.FindElement(By.Id("FirstName")).Clear();
driver.FindElement(By.Id("FirstName")).SendKeys("QA");
driver.FindElement(By.Id("SecondName")).Clear();
driver.FindElement(By.Id("SecondName")).SendKeys("QA");
driver.FindElement(By.Id("LastName")).Clear();
driver.FindElement(By.Id("LastName")).SendKeys("QA");
driver.FindElement(By.CssSelector("input#BirthDay.date-picker")).Clear();
driver.FindElement(By.CssSelector("input#BirthDay.date-picker")).SendKeys("01/01/1900");
driver.FindElement(By.Id("SchoolName")).Click();
driver.FindElement(By.Id("SchoolName")).Clear();
driver.FindElement(By.Id("SchoolName")).SendKeys("mySchool");
driver.FindElement(By.Id("Email")).Clear();
driver.FindElement(By.Id("Email")).SendKeys("");
driver.FindElement(By.Id("Phone")).Clear();
driver.FindElement(By.Id("Phone")).SendKeys("0888123456");
driver.FindElement(By.XPath("//fieldset[@id='PersonalData']/div[16]/span/span/span[2]/span")).Click();
driver.FindElement(By.Id("SendButton")).Click();
try
{
Assert.IsTrue(IsElementPresent(By.CssSelector("span.field-validation-error > span")));
}
catch (AssertFailedException e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.Id("Email")).Click();
string email = "qastudent" + gen.Next(1, 100000) + "@abv.bg";
driver.FindElement(By.Id("Email")).Click();
driver.FindElement(By.Id("Email")).SendKeys(email);
driver.Manage().Cookies.DeleteCookieNamed("ASPXAUTH");
try
{
Assert.IsTrue(Regex.IsMatch(driver.FindElement(By.Id("Email")).Text, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"));
}
catch (AssertFailedException e)
{
verificationErrors.Append(e.Message);
}
try
{
Assert.IsTrue(!IsElementPresent(By.CssSelector("span.field-validation-error > span")));
}
catch (AssertFailedException e)
{
verificationErrors.Append(e.Message);
}
try
{
Assert.IsFalse(Regex.IsMatch(driver.FindElement(By.CssSelector("BODY")).Text, "^[\\s\\S]*Имейл адресът е задължителен\\.[\\s\\S]*$"));
}
catch (AssertFailedException e)
{
verificationErrors.Append(e.Message);
}
driver.Close();
}
示例12: virool
public static void virool(IWebDriver driver)
{
int currentHour = DateTime.Now.Hour;
bool looping = true, looped = false;
int counter = 0;
while (looping)
{
try
{
System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
foreach (String window in windowHandles)
{
IWebDriver popup = driver.SwitchTo().Window(window);
}
try
{
if (driver.Title.Contains("Facebook"))
{
driver.Close();
}
}
catch { }
try
{
driver.SwitchTo().DefaultContent();
}
catch { }
try
{
if (driver.FindElement(By.Id("offerWallContent")).Text == "Please try back later.")
{
looping = false;
}
}
catch { }
Helpers.switchFrameByNumber(driver, 0);
counter = 0;
Helpers.wait(5000);
//ByClass(driver, "thumbnail");
IList<IWebElement> thumbnails = driver.FindElements(By.ClassName("thumbnail"));
Console.WriteLine("Thumbnails Count: " + thumbnails.Count);
if (thumbnails.Count == 0)
{
looping = false;
}
foreach (IWebElement thumbnail in thumbnails)
{
if (counter > thumbnails.Count - 2)
{
thumbnail.Click();
looped = true;
}
counter++;
}
while (looped)
{
//switchFrameByNumber(driver, 0);
Helpers.switchFrameByNumber(driver, 0);
Helpers.switchToBrowserFrameByString(driver, "widgetPlayer");
try
{
IList<IWebElement> h1s = driver.FindElements(By.TagName("h1"));
foreach (IWebElement h1 in h1s)
{
if (h1.Text.Contains("504 Gateway"))
{
driver.SwitchTo().DefaultContent();
Helpers.switchFrameByNumber(driver, 0);
Helpers.ByClass(driver, "close");
looped = false;
looping = false;
}
}
}
catch { }
try
{
IWebElement fbPageUp = driver.FindElement(By.ClassName("fb-share-btn"));
fbPageUp.SendKeys(Keys.PageUp);
Helpers.wait(1000);
fbPageUp.SendKeys(Keys.PageUp);
Helpers.wait(1000);
fbPageUp.SendKeys(Keys.PageUp);
Helpers.wait(1000);
fbPageUp.SendKeys(Keys.PageUp);
Helpers.wait(1000);
}
catch { }
try
//.........这里部分代码省略.........
示例13: switchToAnotherWindow
//切换至另一个窗口 并退出原来窗口
public static void switchToAnotherWindow(IWebDriver driver)
{
IList<string> handlers = driver.WindowHandles;
foreach (var winHandler in handlers)
{
if (winHandler != driver.CurrentWindowHandle)
{
driver.Close();
driver.SwitchTo().Window(winHandler);
}
}
}
示例14: volume11
void volume11(IWebDriver driver)
{
try
{
driver.FindElement(By.PartialLinkText("Volume")).Click();
}
catch { }
while (Helpers.lookFor(driver, "b.v11media.com"))
{
try
{
System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;
foreach (String window in windowHandles)
{
try
{
IWebDriver popup = driver.SwitchTo().Window(window);
}
catch { }
try
{
if (driver.Title.Contains("Facebook"))
{
driver.Close();
}
}
catch { }
try
{
driver.SwitchTo().DefaultContent();
}
catch { }
Helpers.switchFrameByNumber(driver, 0);
try
{
IWebElement dropDownMonth = driver.FindElement(By.ClassName("b_month"));
IWebElement dropDownDay = driver.FindElement(By.ClassName("b_day"));
IWebElement dropDownYear = driver.FindElement(By.ClassName("b_year"));
IWebElement dropDownGender = driver.FindElement(By.ClassName("gender"));
string[] months = { "January", "Febuary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
string[] gender = { "Male", "Female" };
Random random = new Random();
int rndMonth = random.Next(0, 11);
Console.WriteLine(rndMonth);
SelectElement clickThis = new SelectElement(dropDownMonth);
clickThis.SelectByText(months[rndMonth]);
Helpers.wait(1000);
int rndGender = random.Next(0, 1);
Console.WriteLine(rndMonth);
clickThis = new SelectElement(dropDownGender);
clickThis.SelectByText(gender[rndMonth]);
Helpers.wait(1000);
int rndDay = random.Next(1, 28);
clickThis = new SelectElement(dropDownDay);
clickThis.SelectByText(rndDay.ToString());
Helpers.wait(1000);
int rndYear = random.Next(1974, 1994);
clickThis = new SelectElement(dropDownYear);
clickThis.SelectByText(rndYear.ToString());
Helpers.wait(1000);
}
catch { }
try
{
driver.FindElement(By.ClassName("submit")).Click();
}
catch { }
try
{
driver.SwitchTo().DefaultContent();
}
catch { }
Helpers.switchFrameByNumber(driver, 0);
Helpers.switchFrameByNumber(driver, 0);
IList<IWebElement> bolds = driver.FindElements(By.TagName("b"));
foreach (IWebElement bold in bolds)
{
if (bold.Text.Contains("No videos"))
{
Helpers.closeWindows(driver, titles);
volume = true;
}
}
try
{
IList<IWebElement> oLinks = driver.FindElements(By.ClassName("singleselectset_radio"));
Random random = new Random();
int rndClick = random.Next(1, oLinks.Count);
//.........这里部分代码省略.........
示例15: goButton_Click
//.........这里部分代码省略.........
FindAndFillTextBox(ElementLocators.cardNumberTextBox, RandomGeneration.CreditCardNumbers());
new SelectElement(driver.FindElement(ElementLocators.cardMonthDropDown)).SelectByText(RandomGeneration.AbbreviatedMonths());
new SelectElement(driver.FindElement(ElementLocators.cardYearDropDown)).SelectByText("2025");
};
FindAndFillTextBox(ElementLocators.firstReferenceNameTextBox, string.Format("{0} {1}", RandomGeneration.FirstName(), RandomGeneration.LastName()));
FindAndFillTextBox(ElementLocators.secondReferenceNameTextBox, string.Format("{0} {1}", RandomGeneration.FirstName(), RandomGeneration.LastName()));
if (this.coApplicantComboBox.SelectedIndex == HAS_COAPPLICANT)
{
FindAndFillTextBox(ElementLocators.coApplicantFirstNameTextBox, RandomGeneration.FirstName());
FindAndFillTextBox(ElementLocators.coApplicantLastNameTextBox, RandomGeneration.LastName());
FindAndFillTextBox(ElementLocators.coApplicantEmployerNameTextBox, RandomGeneration.EmployerNames());
FindAndFillTextBox(ElementLocators.coApplicantHireDateTextBox, RandomGeneration.BirthDateWithLeadingZeros());
FindAndFillTextBox(ElementLocators.coApplicantDateOfBirthTextBox, RandomGeneration.BirthDateWithLeadingZeros());
FindAndFillTextBox(ElementLocators.coApplicantSocialSecurityNumberTextBox, RandomGeneration.SocialSecurityNumber());
FindAndFillTextBox(ElementLocators.coApplicantMonthlyIncomeTextBox, RandomGeneration.MonthlyIncome());
FindAndFillTextBox(ElementLocators.coApplicantPrimaryPhoneTextBox, RandomGeneration.PhoneNumber());
FindAndFillTextBox(ElementLocators.coApplicantSecondaryPhoneTextBox, RandomGeneration.PhoneNumber());
FindAndFillTextBox(ElementLocators.coApplicantEmailAddressCheckBox, RandomGeneration.EmailAddress());
FindAndFillTextBox(ElementLocators.coApplicantStreetAddressTextBox, RandomGeneration.PhysicalAdress());
FindAndFillTextBox(ElementLocators.coApplicantApartmentBuildingFloorTextBox, RandomGeneration.RandomSingleInteger(1, 10).ToString() + "B");
FindAndFillTextBox(ElementLocators.coApplicantCityTextBox, RandomGeneration.City());
new SelectElement(driver.FindElement(ElementLocators.coApplicantStateDropDown)).SelectByText(RandomGeneration.States());
FindAndFillTextBox(ElementLocators.coApplicantZipTextBox, RandomGeneration.PostalCode());
}
FindAndFillTextBox(ElementLocators.firstReferencePhoneNumberTextBox, RandomGeneration.PhoneNumber());
FindAndFillTextBox(ElementLocators.secondReferencePhoneNumberTextBox, RandomGeneration.PhoneNumber());
FindAndFillTextBox(ElementLocators.employerNameTextBox, RandomGeneration.EmployerNames());
FindAndFillTextBox(ElementLocators.employerPhoneTextBox, RandomGeneration.PhoneNumber());
FindAndFillTextBox(ElementLocators.hireDateTextBox, RandomGeneration.BirthDateWithLeadingZeros());
FindAndFillTextBox(ElementLocators.lastPayDateTextBox, lastPayDate);
FindAndFillTextBox(ElementLocators.nextPayDateTextBox, nextPayDate);
new SelectElement(driver.FindElement(ElementLocators.payFrequencyDropDown)).SelectByText(payFrequencyTypeText);
wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.submitButton)).Click();
try
{
wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.continueButton)).Click();
}
catch (WebDriverException)
{
//We don't care if this dialogue is here or not. We just want
//To click it IF it pops into view. That is the reasoning behind
//this try catch.
}
try
{
wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.submitButton)).Click();
}
catch (WebDriverException)
{
//just here to prevent app from breaking if there is no application review page
};
#endregion FormFill
#region Output
try
{
IWebElement referenceNumber = wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.referenceNumber));
IWebElement preApprovalCode = wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.preApprovalCode));
IWebElement approvalAmount = wait.Until(ExpectedConditions.ElementIsVisible(ElementLocators.approvalAmount));
approvalAmountList.Add(approvalAmount.Text);
referenceNumberList.Add(referenceNumber.Text);
preApprovalCodeList.Add(preApprovalCode.Text);
}
catch
{
//here to prevent app from breaking if the applicant isnt auto approved
}
#endregion Output
driver.Close();
driver.Quit();
}//End for loop.
//PrintListContent(approvalAmountsList, referenceNumberList, preApprovalCodeList);
foreach(string item in referenceNumberList)
{
// accountOutputTextBox.Text = String.Join(Environment.NewLine, referenceNumber, preApprovalCode, approvalAmount);
this.accountOutputTextBox.AppendText(item + Environment.NewLine);
}
}