Reputation: 1
This is my code, when it gets to Switchto().Alert()
there is an error saying 'No such alert'
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Add Document'])[1]/following::button[1]")).Click();
**driver.SwitchTo().Alert().Accept();**
var signFrame = driver.FindElement(By.Id("hsEmbeddedFrame"));
driver.SwitchTo().Frame(signFrame);
driver.FindElement(By.XPath("(.//*[normalize-space(text()) and normalize-space(.)='Istrong textnitials'])[1]/preceding::li[1]")).Click();strong text
Upvotes: 0
Views: 480
Reputation: 5909
You may need to wait for the alert to exist before clicking on it:
using OpenQA.Selenium.Support.UI;
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
// alert is present will automatically switch to the alert
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.AlertIsPresent());
// the below line is no longer necessary
// driver.SwitchTo().Alert().Accept();
If this still throws NoSuchAlertException
, then the popup appearing may not truly be an alert, but possibly an HTML modal instead -- in which case, you can inspect it & use Selenium to find an appropriate selector to accept it.
Upvotes: 4