Search This Blog

Thursday, February 16, 2012

Handling Permission denied error for error using Seleium WebDriver

Depending on the application page structure you may encounter with below error sometimes on FF (may be other browsers) latest versions while trying to clicking on any element, and there is no consistent resolution from Selenium Team yet, and we need to live with some work around for this.

Errors:
  1. Error: Permission denied for <https://www.facebook.com> to get property HTMLDocument.compatMode' when calling method: [wdIMouse::move]" 
  2. Error: Permission denied for <http://xxx.xxx.com> to get property Location.href [error] Permission denied for <http://xxx.xxx.com> to get property Location.href 
  3. WebDriverException: Message: u'Permission denied for <https://dashboard.sitesupport.my> to get property Window.mozInnerScreenX'
  4. Exception thrown org.openqa.selenium.WebDriverException: Permission denied for <http://www.facebook.com> to get property Window.frameElement;

Resolutions:
  1. First one works sometimes but may not all the times. Just wrap your click statement in try/catch block in spite of the error, element will be clicked successfully.
  2. Using JavaScript executor you can click on such elements using below code.
String windowHandle=driver.getWindowHandle(); //driver is webdriver object here
            
WebElement element = driver.findElement(By.xpath(xpath));
Actions builder = new Actions(driver);   
builder.moveToElement(element).build().perform();
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("var evt = document.createEvent('MouseEvents');""evt.initMouseEvent('click',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);""arguments[0].dispatchEvent(evt);", element);
                 
driver.switchTo().window( windowHandle );  

6 comments:

  1. I know this is 7 months old, however, I was having this issue with developer.linkedin.com and the easier work-around i've found was doing this:

    WebElement submitButton = driver.findElement(By.className("btn-primary"));

    submitButton.sendKeys(Keys.ENTER);

    ReplyDelete
  2. Excellent Post. Also visit http://whiteboxqa.com/selenium.

    ReplyDelete
  3. Fantastic article ! You havemade some very astute statements and I appreciate the the effort you have put into your writing. Its clear that you know what you are writing about. I am excited to read more of your sites content.

    Big data online training

    ReplyDelete
  4. Hey very nice blog!!
    Hi there,I enjoy reading through your article post, I wanted to write a little comment to support you and wish you a good continuationAll the best for all your blogging efforts.
    Appreciate the recommendation! Let me try it out.
    Keep working ,great job!
    Hadoop training

    ReplyDelete
  5. Hi
    I read this post two times.
    I like it so much, please try to keep posting.
    Let me introduce other material that may be good for our community.

    Microsoft dynamics training

    ReplyDelete
  6. je.executeScript("function detectLink1(){ var anchor = document.getElementsByTagName('"+tag+"');var a; for(i=0;i<anchor.length;i++){if ((anchor[i].innerHTML).indexOf('"+searchText+"') != -1) {a=anchor[i];break;}}a.click();}detectLink1();");

    is not clicking the element, can anyone help?

    ReplyDelete