public bool Alert() { bool presentFlag = false; Alert alert = null; try { // Check the presence of alert alert = driver.SwitchTo().Alert(); // if present consume the alert alert.Accept(); presentFlag = true; } catch (NoAlertPresentException ex) { // Alert present; set the flag // Alert not present Console.WriteLine(ex.ToString()); Console.Write(ex.StackTrace); } return(presentFlag); }
/// <summary> /// Dismisses the alert /// </summary> public void AlertDismiss() { QA.IAlert alert = null; alert = wd.SwitchTo().Alert(); if (alert != null) { alert.Dismiss(); } }
/// <summary> /// Accepts the alert /// </summary> public void AlertAccept() { QA.IAlert alert = null; alert = wd.SwitchTo().Alert(); if (alert != null) { alert.Accept(); } }
/// <summary> /// Dismisses the alert /// </summary> protected void AlertDismiss() { QA.IAlert alert = null; alert = _WebDriver.SwitchTo().Alert(); if (alert != null) { alert.Dismiss(); } }
/// <summary> /// Accepts the alert /// </summary> protected void AlertAccept() { QA.IAlert alert = null; alert = _WebDriver.SwitchTo().Alert(); if (alert != null) { alert.Accept(); } }
/// <summary> /// 未使用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { _url = "https://www.net.city.nagoya.jp/cgi-bin/sp01001"; OpenQA.Selenium.Chrome.ChromeDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(); driver.Url = _url; //利用者番号 IWebElement id = driver.FindElement(By.Name("id")); id.SendKeys("1278192"); //暗証番号 IWebElement pass = driver.FindElement(By.Name("pass")); pass.SendKeys("1234"); //地域 SelectElement area = new SelectElement(driver.FindElement(By.Name("area"))); area.SelectByValue("04"); //利用施設 SelectElement sisetu = new SelectElement(driver.FindElement(By.Name("sisetu"))); sisetu.SelectByValue("5102"); //種目 SelectElement syumoku = new SelectElement(driver.FindElement(By.Name("syumoku"))); syumoku.SelectByValue("001"); //利用月日 SelectElement month = new SelectElement(driver.FindElement(By.Name("month"))); month.SelectByValue("09"); SelectElement day = new SelectElement(driver.FindElement(By.Name("day"))); day.SelectByValue("06"); //供用区分 SelectElement time = new SelectElement(driver.FindElement(By.Name("time"))); time.SelectByValue("03"); //申込 IWebElement B1 = driver.FindElement(By.Name("B1")); B1.Click(); //ダイアログ OpenQA.Selenium.IAlert alert = driver.SwitchTo().Alert(); alert.Accept(); }
/// <summary> /// Get the alert text /// </summary> /// <returns></returns> public string GetAlertString() { string theString = string.Empty; QA.IAlert alert = null; alert = wd.SwitchTo().Alert(); if (alert != null) { theString = alert.Text; } return(theString); }
public void HandleAlertPopUp() { try { OpenQA.Selenium.IAlert alert = driver.SwitchTo().Alert(); alert.Accept(); } catch (NoAlertPresentException ex) { throw new Exception(ex.Message); } }
/// <summary> /// Get the alert text /// </summary> /// <returns></returns> protected string GetAlertString() { string theString = string.Empty; QA.IAlert alert = null; alert = _WebDriver.SwitchTo().Alert(); if (alert != null) { theString = alert.Text; } return(theString); }
public string ReadAndHandleAlert() { try { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); wait.Until(ExpectedConditions.AlertIsPresent()); IAlert alert = driver.SwitchTo().Alert(); string strWarning = alert.Text; alert.Accept(); return(strWarning); } catch (Exception) { return("Alert not displayed"); } }
/// <summary> /// 利用者情報入力にアクセスし新パスワードの登録を行う /// </summary> /// <param name="entryId">入力利用者番号</param> /// <param name="entryPass">入力暗証番号</param> /// <param name="entryNewPass">入力新パスワード</param> private void RegisterNewPW(string entryId, string entryPass, string entryNewPass) { try { //画面遷移 this._driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["url_sp10001"]); //利用者番号 IWebElement id = this._driver.FindElement(By.Name("id")); id.SendKeys(entryId); //暗証番号 IWebElement pass = this._driver.FindElement(By.Name("pass")); pass.SendKeys(entryPass); //OK IWebElement B1 = this._driver.FindElement(By.Name("B1")); B1.Click(); //現行の情報でログインできたかを判定 if (this._driver.PageSource.IndexOf("入力されたデータに誤りがあります。") > 0) { //何もしない return; } //パスワード IWebElement pass1 = this._driver.FindElement(By.Name("pass1")); pass1.SendKeys(entryNewPass); //パスワード確認 IWebElement pass2 = this._driver.FindElement(By.Name("pass2")); pass2.SendKeys(entryNewPass); //OK B1 = this._driver.FindElement(By.Name("B1")); B1.Click(); //登録が正常に完了したかを判定 if (this._driver.PageSource.IndexOf("暗証番号からパスワードへの移行が完了しました。") > 0) { //何もしない return; } } catch (NoSuchElementException ex1) { this._log.Error("RegisterNewPW - error", ex1); //要素取得エラーは無視 } catch (UnhandledAlertException ex2) { this._log.Error("RegisterNewPW - error", ex2); //ダイアログを取得し閉じる OpenQA.Selenium.IAlert alert = this._driver.SwitchTo().Alert(); alert.Accept(); } catch (NoAlertPresentException ex3) { this._log.Error("RegisterNewPW - error", ex3); //要素取得エラーは無視 } }
/// <summary> /// 抽選申し込み情報の入力を行い申し込みボタンを押下する /// </summary> /// <param name="entryId">入力利用者番号</param> /// <param name="entryPass">入力暗証番号</param> /// <param name="entryMonth">入力月</param> /// <param name="entryDay">入力日</param> /// <param name="entryArea">入力地域コード</param> /// <param name="entrySisetu">入力施設コード</param> /// <param name="entryTime">入力時間帯コード</param> private void Register(string entryId, string entryPass, string entryMonth , string entryDay, string entryArea, string entrySisetu, string entryTime) { try { //画面遷移 this._driver.Navigate().GoToUrl(ConfigurationManager.AppSettings["url_sp01001"]); //利用者番号 IWebElement id = this._driver.FindElement(By.Name("id")); id.SendKeys(entryId); //暗証番号 IWebElement pass = this._driver.FindElement(By.Name("pass")); pass.SendKeys(entryPass); //地域 SelectElement area = new SelectElement(this._driver.FindElement(By.Name("area"))); area.SelectByValue(entryArea); //利用施設 SelectElement sisetu = new SelectElement(this._driver.FindElement(By.Name("sisetu"))); sisetu.SelectByValue(entrySisetu); //種目 SelectElement syumoku = new SelectElement(this._driver.FindElement(By.Name("syumoku"))); syumoku.SelectByValue(ConfigurationManager.AppSettings["syumoku"]); //利用月日 SelectElement month = new SelectElement(this._driver.FindElement(By.Name("month"))); month.SelectByValue(entryMonth); SelectElement day = new SelectElement(this._driver.FindElement(By.Name("day"))); day.SelectByValue(entryDay); //供用区分 SelectElement time = new SelectElement(this._driver.FindElement(By.Name("time"))); time.SelectByValue(entryTime); //申込 IWebElement B1 = this._driver.FindElement(By.Name("B1")); B1.Click(); //ダイアログ WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(Double.Parse(ConfigurationManager.AppSettings["wait_seconds"]))); IAlert alert = wait.Until(drv => drv.SwitchTo().Alert()); string alertText = alert.Text; alert.Accept(); // B1 = this._driver.FindElement(By.Name("B1")); //ダイアログ取得前に待機 //WebDriverWait wait = new WebDriverWait(this._driver, TimeSpan.FromSeconds(Double.Parse(ConfigurationManager.AppSettings["wait_seconds"]))); //wait.until(ExpectedConditions.alertIsPresent()); // WebDriverWait wait = new WebDriverWait(this._driver, TimeSpan.FromSeconds(3)); // IWebElement element = wait.Until(driver => driver.FindElement(By.Name("q"))); // IWebElement element = wait.Until(ExpectedConditions.AlertIsPresent<IWebDriver>()); // IWebElement element = wait.Until<>(ExpectedConditions.AlertIsPresent<IWebDriver>()); // OpenQA.Selenium.IAlert alert = this._driver.SwitchTo().Alert(); // alert.Accept(); //結果取得 IWebElement return01001 = this._driver.FindElement(By.Name("return01001")); } catch (NoSuchElementException ex1) { this._log.Error("Register - error", ex1); //要素取得エラーは無視 } catch (UnhandledAlertException ex2) { this._log.Error("Register - error", ex2); //ダイアログを取得し閉じる OpenQA.Selenium.IAlert alert = this._driver.SwitchTo().Alert(); alert.Accept(); } catch (NoAlertPresentException ex3) { this._log.Error("Register - error", ex3); //要素取得エラーは無視 } }