King81
King81

Reputation: 83

Selenium WebDriver - Unable to find and click a Submit button on modal dialog

I've also implemented an Implicit Wait button it doesn't seem to work:

driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

Result StackTrace:

at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at `OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)`
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath)
   at OpenQA.Selenium.By.<>c__DisplayClass19_0.<XPath>b__0(ISearchContext context)
   at OpenQA.Selenium.By.FindElement(ISearchContext context)
   at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)

Test method TestCases.InsTerminationCollab threw exception:

OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id='create - experiment - confirm - title']"}
(Session info: chrome=64.0.3282.167)
(Driver info: chromedriver=2.35.528161 
(5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.14393 x86_64)

HTML Code:

<div class="modal-content" role="document"><div class="modal-header"><button type="button" class="close"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button><h4 id="create-experiment-confirm-title" class="modal-title">Do you wish to proceed with the following selections?</h4></div><form class="form-horizontal" method="post"><div class="modal-body">

<button type="submit" title="Create experiment" id="create-experiment-confirm-submit" class="btn btn-primary">Submit</button>

Upvotes: 1

Views: 1486

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193088

To locate and click the Submit button on modal dialog you can use the following line of code :

wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
element = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//form[@class='form-horizontal']//button[@class='btn btn-primary' and @id='create-experiment-confirm-submit']")));
element.Click();

Upvotes: 1

Related Questions