I'm trying to automate a scenario for some web pages using C#, Selenium and Chrome Webdriver, where Submit button click on the page will submit the sendkeys values.
however when Submit is clicked, it's throwing an UnpackAndThrowOnError
error in Visual Studio Test explorer Window (Nunit
).
<button type="submit" class="btn btn-primary mr-4" name="postType" value="Submit">Submit<span class="glyphicon glyphicon-floppy-save"></span></button>
Detailed Error Description:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(ResponseerrorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary'2 parameters)
at OpenQA.Selenium.Remote.RemoteWebElement.Execute(String commandToExecute, Dictionary'2 parameters)<br>
at OpenQA.Selenium.Remote.RemoteWebElement.Click()
at Onrsr.Specflow.Sampletest.occurrence() in C:\Users\manish.sharma\source\repos\Onrsr.Specflow\Onrsr.Specflow\Sampletest.cs:line 180
I've tried the below code options, but they all are failing at submitBtnReview.Click()
IWebElement submitBtnReview = driver.FindElement(By.XPath("//button[contains(.,'Submit')]"));
submitBtnReview.Click();
IWebElement submitBtnReview = driver.FindElement(By.CssSelector("input[value='Submit']"));
submitBtnReview.Click();
IWebElement submitBtnReview = driver.FindElement(By.XPath("//button[@class='btn btn-primary mr-4']"));
submitBtnReview.Click();
IWebElement submitBtnReview = driver.FindElement(By.CssSelector("input[type='submit'][value='Submit']"));
submitBtnReview.Click();
I've also tried using submitBtnReview.Submit()
with the IwebElement
above, however it's crashing the page.
I'm using latest version of Selenium.WebDriver (3.141.0) and Selenium.Chrome.WebDriver (2.43.0), and using chrome version 70.0.3538.102 (Official Build) (64-bit) on windows 10 machine.
Any idea what I might be doing wrong here?
[05/12/2018] - thank you for all valuable feedbacks - I've now also tried the below and they are failing at submitBtnReview.Click()
with a new error:
Message: OpenQA.Selenium.WebDriverException : unknown error: Element <button type="submit" class="btn btn-primary mr-4" name="postType" value="Submit">...</button> is not clickable at point (1792, 876). Other element would receive the click: <footer class="border-top bg-white">...</footer> (Session info: chrome=70.0.3538.110) (Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT 10.0.17134 x86_64)
IWebElement submitBtnReview = driver.FindElement(By.CssSelector("button[type='submit'][value='Submit'][name='postType']"));
IWebElement submitBtnReview = driver.FindElement(By.XPath("//button[contains(@class, 'btn') and contains(@class, 'btn-primary') and contains(@class, 'mr-4')]"));
IWebElement submitBtnReview = driver.FindElement(By.XPath("//button[@class='btn btn-primary mr-4']"));
IWebElement submitBtnReview = new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[@class='btn btn-primary mr-4' and @name='postType'][normalize-space()='Submit']")));
IWebElement submitBtnReview = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(element_is_present(By.CssSelector("button[type='submit'][value='Submit'][name='postType']")))
public static Func<IWebDriver, IWebElement> element_is_present(By by)
{ return driver =>
{ IWebElement element = driver.FindElement(by);
try
{ if (element != null && element.Displayed && element.Enabled)
{ return element;
}
else
{ return null;
}
}catch (StaleElementReferenceException)
{ return null;
}
};
}
Setting some breakpoints, showing submitBtnReview
LocationOnScreen coordinates with a new error, and this might be related.
LocationOnScreen = '((OpenQA.Selenium.Remote.RemoteCoordinates)((OpenQA.Selenium.Remote.RemoteWebElement)submitBtnReview ).Coordinates).LocationOnScreen' threw an exception of type 'System.NotImplementedException'
Submit button details from debugging:
Hope this additional information helps in finding the cause.