Reputation: 41
I am using Selenium Webdriver using C#, but selenium isn't identifying my Modal Window.
I have tried:
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
But it doesn't work. In the code the modal has 'ID' but, it doesn't work either.
I need identify the modal and click in the button.
Upvotes: 2
Views: 855
Reputation: 193088
As per the HTML you have shared to click on the button with text as Close you need to induce WebDriverWait for the desired element to be clickable and you can use either of the following solutions:
Using CssSelector
:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.close[data-dismiss='modal'][aria-label='Close']"))).Click();
Using XPath
:
new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[@class='close' and @data-dismiss='modal'][@aria-label='Close']"))).Click();
Upvotes: 1