I'm writing selenium code in C# to interact with a form
This is the submit button:
<input type="submit" value="Submit" onclick="return confirm('Submit?');" class="SubmitButton">
This is my Selenium code to click the submit button.
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
Yet when I do, the 'ok' button is not clicked. Instead the dialogue box disappears and the form acts as if the submit input was never clicked. What am I doing wrong?
I don't know why your code was not working(my be version specific), Its working fine for me.
IAlert alert = driver.SwitchTo().Alert();
alert.Accept();
Any ways, you can do this way also,
SendKeys.SendWait("{ENTER}");
but before doing this make sure "System.Windows.Forms.dll" is added in your project References and also make sure your app is active when running, mean don't click on other window when popup appears and don't let your computer to be sleep.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With