Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium RC click command gets stuck

Solution: Today (2011-04-13) handles Selenium RC the confirmation boxes under Firefox 4 badly. I had to change back to Firefox 3.16 and then this problem disappears. Thanks again.

Original Question:

Hello Selenium gurus,

I am trying to execute an automated browser test from Java using Selenium 2.0b3 as the Java client and standalone server too.
The server starts a Firefox 4 with a specific profile.

The test is stuck at a "click" command; it waits and no timeout/exception/any error happens. During this click comes up a confirmation box, so I guess that is the problem, but I do not know why this gets stuck. In Selenium IDE comes not this confirmation box, only in RC.

The problem is not that, that the click does not happens (because the confirmation box appears), but that this confirmation box hangs. I tried these but did not help:

selenium.click("css=div[id=command_Delete]");
selenium.click("id=command_Delete");
String JSscript = "jQuery('#command_Delete').click();" // See http://api.jquery.com/click/
selenium.runScript(JSscript);

These are just ways how to start the click. Maybe I have to start a different Thread according these link: http://www.sqaforums.com/showflat.php?Cat=0&Number=567974&an=&page=0&vc=1

Thanks: Andras

Java code:

selenium.click("//div[@id='command_Delete']/span");
//stucks here
//so this is not reached:
String confirmation = selenium.getConfirmation();

HTML:

<div id="command_Delete" class="...">
    <div>...</div>
    <span>Delete</span>
    <div>...</div>
    <br><br>
</div>

Javascript:

<script type="text/javascript">
    $('command_Delete').addEvent('click',function(){
        var isConfirmTrue = confirm('Do you want to delete?');
        if (isConfirmTrue) {
            var myForm = getFormObj(document, "deleteForm");
            submitForm(myForm);
        }
    });
</script>

And in the Java, it hangs waiting the selenium rc to answer:

HttpURLConnection.getInputStream() line: 912 [local variables unavailable]  
HttpURLConnection(HttpURLConnection).getResponseCode() line: 367 [local variables unavailable]  
HttpCommandProcessor.getResponseCode(HttpURLConnection) line: 147   
HttpCommandProcessor.getCommandResponseAsString(String) line: 167   
HttpCommandProcessor.executeCommandOnServlet(String) line: 107  
HttpCommandProcessor.doCommand(String, String[]) line: 89   
DefaultSelenium.click(String) line: 167 
...
like image 254
Andras Avatar asked Sep 09 '26 17:09

Andras


2 Answers

Have you tried replacing

selenium.click("//div[@id='command_Delete']/span");

with

selenium.click("id=command_Delete");

?

It seems to me that since the event is binded to the div itself that should work.

Additionally, you can execute the click action directly by doing this, I'm using jQuery since you seem to already have it loaded on the page and it makes things easier (especially for cross-browser testing):

String JSscript = "jQuery('#command_Delete').click();" // See http://api.jquery.com/click/
selenium.runScript(JSscript);

You'd just need to evaluate if this solution is good for you.

like image 71
Argote Avatar answered Sep 12 '26 21:09

Argote


If a confirmation box is popping up the test will block until that confirmation box has been removed. You can do a quick manual test to see if this is your problem.

Run your test and when the confirmation box comes up manuall y interact with it, if everything else is fine the test should continue from that point as per normal.

Selenium is waiting for the page to load, but the pop up box is blocking the page from loading which is eventually resulting in a timeout.

You can try and work around this using selenium.chooseOkOnNextConfirmation(); before your click.

like image 28
Ardesco Avatar answered Sep 12 '26 21:09

Ardesco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!