Saturday, March 6, 2010

Permission denied error after clicking on link when using selenium

Selenium throws a Permission Denied error after clicking, if we are not waiting for page to load before accessing the GUI. In most of the cases it works fine for Firefox, but with IE, this fails.

Consider the following piece of code:

//click function here take care of sending click command to selenium RC Server
$object->click('link=www.somelink.com');

//Type command sends USERNAME to the Selenium RC Server to be typed in input box with ID: username
$object->type('id=username', 'USERNAME');

Now the above mentioned code works good for Firefox, but it throws Permission denied error with IE.

Reason for that is as we have clicked on the link, and the page has to refresh, therefore when we try to type into some field on GUI that has not loaded yet, selenium throws Permission denied error.

Simple solution to above is to use clickAndWait command instead of just click, which will give some time to GUI to get refreshed or load before executing the next command.

so our new code will look like this:

//It clicks on the link and then waits for page to load dynamically for default time out value of selenium
$object->click_and_wait('link=www.somelink.com');
$object->type('id=username', 'USERNAME');

Now it works fine for both IE and Firefox.

However for applications that involve AJAX or changing display properties to block or none on click, this solution does not work.

For these, we need to either use explicit sleep($time_in_seconds) command [ Not suggested though ], or we can wait for some element on the refreshed GUI, which will make the page to wait before actually typing in the field.

Modified code will look something similar to as mentioned below:

$object->click('link=www.somelink.com');

//This will make the page to wait to load dynamically till HTML Field id=username becomes accessible and will solve our permission denied problem.

$object->wait_for_element('id=username');

$object->type('id=username');

Hope it helps. Let me know if you are unable to fix any Permission denied error with above mentioned solution.

Thanks,
QuickSilver1183
QuickSilver1183@gmail.com

3 comments:

  1. Hi,

    Any idea as why this happens intermittently in IE ?
    If its consistent then its a Selenium bug and in case not then its a product bug. How do you catch such errors instead of adding sleeps in the code ?

    ReplyDelete
  2. if I wait for the object its giving the error :

    *ERROR: Selenium failure. Please report to the Selenium Users forum at* [ http://forums.openqa.org ]*, \\ with error details from the log window. The error message is: Invalid argument.*

    So sleep is the only solution what i will be left with?

    ReplyDelete
  3. Hello,

    Am getting permission denied error in IE8 using selenium 1. In my case this happens only when the element clicked initiates a window.open... Any idea why?

    Thanks.

    ReplyDelete