Selenium Script to remove users from all groups in Confluence.

Hello Friends,

This is one of the tutorials for Confluence users where they can use the Selenium script as an automation for removing the users from all the groups in Confluence. In this tutorial, I have used one xml file which will contain the usernames and one java file that will contain the selenium script and other java code. The java code will fetch the usernames from the xml file and will perform the required actions at confluence end. The other selenium related details have already been discussed in my previous blogs. So, without discussing it further, lets move to the point.

Following is the xml file named removeUser.xml

In the above file, we have taken 3 users. The java and selenium code for this is in file that contains the following:


package com.code2java.confluence;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

import java.util.regex.Pattern;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class ConfluenceRemoveUser extends SeleneseTestCase {
public void setUp() throws Exception {
selenium = new DefaultSelenium(“localhost”, 4444, “*iexplore”, “https://localhost/”);

public void testConfluenceRemoveUser() throws Exception {

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File(“removeUser.xml”));

NodeList listOfUsers = doc.getElementsByTagName(“username”);
int totalOptions = listOfUsers.getLength();
System.out.println(“totalOptions is “+totalOptions);“/confluence/login.action”);
selenium.type(“id=os_username”, “username”);
selenium.type(“id=os_password”, “password”);“id=loginButton”);
for(int s=0; s<listOfUsers.getLength() ; s++)
Node firstOptionNode = listOfUsers.item(s);

if(firstOptionNode.getNodeType() == Node.ELEMENT_NODE)
Element firstUserElement = (Element)firstOptionNode;
NodeList firstNameList = firstUserElement.getElementsByTagName(“list”);
Element firstNameElement = (Element)firstNameList.item(0);
NodeList textFNList = firstNameElement.getChildNodes();

String nameOfOption = ((Node)textFNList.item(0)).getNodeValue().trim();
System.out.println(“The name of user is : “+nameOfOption);

String[] userList = nameOfOption.split(“,”);
for(int i=0;i<userList.length;i++)
System.out.println(“The user is “+userList[i]);“/confluence/admin/users/viewuser.action?username=”+userList[i]);
selenium.waitForPageToLoad(“30000”);“link=Edit Groups”);
catch(Exception e)
System.out.println(” EXCEPTION :”+ e.getMessage ());
{“css=#logout-link > span”);

catch (SAXParseException err)
System.out.println (“** Parsing error” + “, line “+ err.getLineNumber () + “, uri ” + err.getSystemId ());
System.out.println(” ” + err.getMessage ());
catch(SAXException ex)
Exception x = ex.getException ();
((x == null) ? ex : x).printStackTrace ();
catch (Throwable t)
t.printStackTrace ();

public void tearDown() throws Exception {


Here, we are reading the users from the xml file and then iterating it via for loop and then performing the selenium script action on them. This is really very much time saving and will help perform your job within time. The same script can be used for adding the users in confluence with little changes.

Hope this will help you.


Nikhil Naoghare

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.