Inside the deleteImage2 method, the first if statement has a
javascript confirm() call. This is what is creating the dialog. This
is javascript and Selenium can handle this without any problems.
Somewhere you have a web element which triggers the call to
deleteImage2(). It might be something like clicking a button. the
<BUTTON> tag will have an onclick attribute. Whatever it is that
causes deleteImage2() to be called, you need the code to handle the
event. So lets say the locator for the 'button' is stored in
deleteButtonLocator then your code might look like:
driver.findElement(deleteButtonLocator).click(); // causes the
dialog to appear
Alert a = driver.switchTo().alert(); // switch focus to the dialog
String text = a.getText(); // get the text for the dialog
a.accept(); // click the OK button
// a.dismiss(); // click the Cancel button
If you want to click Cancel, just comment out the a.accept() and
uncomment the a.dismiss().
On May 16, 10:42 pm, testingzeal <
jselen...@gmail.com> wrote:
> I tried this and it doens't work,by the way it is confirm dialog
>
> Robot robot = new Robot();
> robot.keyPress(KeyEvent.VK_ENTER);
>
> Here is the function where the confirm is =================
>
> function deleteImage2(id)
>
> {
>
> if(confirm('Are you sure you want to delete this image?')) {
>
> document.forms.imageForm2.deleteImageID.value=id;
>
> document.forms.imageForm2.catID.value='3';
>
> document.forms.imageForm2.submit();
>
> }
> }
>
> ==== When i record in IDE it shows this line ,but doesn't work when i paste
> this code in my method,it blows up
> assertTrue(closeAlertAndGetItsText().matches("^Are you sure you want to
> delete this image[\\s\\S]$"));
>
> Any help please ???
>
>
>
>
>
>
>
> On Thursday, May 16, 2013 4:34:53 AM UTC-6, CVQ PRS wrote:
>
> > Hello,
>
> > as Mark said, selenium does not provide support for this kind of popups.
>
> > If this is a browser pop up where you have to only press
> > Yes|No|Accept|Cancel etc. you can use robot:
> >
http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html
>
> > Thanks,
> > Piotr
>
> > 2013/5/16 Mark Collin <
mark....@lazeryattack.com <javascript:>>
>
> >> Selenium can only interact with JavaScript popups, not browser popups.
>
> >> If you are getting a browser popup I would suggest that your test is
> >> probably not doing anything particularly useful (i.e. you are tesing the
> >> browsers functionality rather than your websites functionality).
>
> >> On 16/05/2013 00:10, testingzeal wrote:
>
> >> driver.switchTo().alert().accept(); is not working in chrome browser.I
> >> checked with my dev guy and he says it is a browser pop up.
>
> >> Any ideas??
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to
webdriver+...@googlegroups.com <javascript:>.
> >> To post to this group, send email to
webd...@googlegroups.com<javascript:>
> >> .
> >> Visit this group athttp://
groups.google.com/group/webdriver?hl=en.
> >> For more options, visithttps://
groups.google.com/groups/opt_out.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to
webdriver+...@googlegroups.com <javascript:>.
> >> To post to this group, send email to
webd...@googlegroups.com<javascript:>
> >> .
> >> Visit this group athttp://
groups.google.com/group/webdriver?hl=en.
> >> For more options, visithttps://
groups.google.com/groups/opt_out.