Selenium script to add Custom Field Options in JIRA.

Hello Friends,

This is one of my tutorials regarding the use of Selenium script in the Jira Configuration. Most of the Jira users may know about the Cascading Type of the Custom fields, there we need to add multiple options against the single one. Now, doing this configuration manual y is really a time consuming job. So, to avoid this, we can use the Selenium Script. All the manual work will be replaced by a single script and it will do everything for you in a very less time.

To use this script you need to have some basic knowledge of the Selenium IDE. I have explained the same in my previous articles, please go through it before implementing this. Here, we will be reading the custom fields options from the simple xml file, where the first Option will represent the Main Category and the remaining will be its sub-categories. The XML file will be as:

The folder structure is explained in the previous article.

Now, we need to add the java file which also includes the code to read the data from XML along with the Selenium script code. You can get the code using the Selenium IDE from Firefox too. I have already discussed this in my articles earlier.

Following is the java code for adding the Options to custom field.


package com.code2java.jira;

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.regex.Pattern;
import org.w3c.dom.*;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

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

public void testCascadingOptions() throws Exception
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new File(“book.xml”));

NodeList listOfOptions = doc.getElementsByTagName(“option”);
int totalOptions = listOfOptions.getLength();“/jira/login.jspa”); //Home page of your Jira Application“link=Log In”);
selenium.type(“id=login-form-username”, “jira_admin_user”);
selenium.type(“id=login-form-password”, “jira_password”);“id=login-form-submit”);
selenium.type(“id=login-form-authenticatePassword”, “jira_password”);“id=authenticateButton”);
//This link may vary. Please check for this link. here 12310 is the custom field ID.“/jira/admin/ConfigureCustomField!default.jspa?customFieldId=12310”);

for(int x=0; x<listOfOptions.getLength() ; x++)
Node firstOptionNode = listOfOptions.item(x);
String nodeNames = “one,two,three,four,five,six,seven,eight,nine,ten”;
String[] listNodes = null;
listNodes = nodeNames.split(“,”);

for(int i=0;i<listNodes.length;i++)
{“link=Edit Options”);

if(firstOptionNode.getNodeType() == Node.ELEMENT_NODE)
Element firstNodeElement = (Element)firstOptionNode;
NodeList firstOptionList = firstNodeElement.getElementsByTagName(listNodes[i]);
Element firstOptionElement = (Element)firstOptionList.item(0);
NodeList textList = firstOptionElement.getChildNodes();
String nameOfOption = ((Node)textList.item(0)).getNodeValue().trim();
System.out.println(“The name of Category is : “+nameOfOption);
String[] options = null;
options = nameOfOption.split(“,”);
boolean flag = true;

for(int j=0;j<options.length;j++)
System.out.println(“The Values of Options “+j+” are “+options[j].trim());
if(j ==0)
selenium.type(“name=addValue”, options[0]);“id=add_submit”);
{“css=select”, “label=”+options[0]);
selenium.type(“name=addValue”, options[j]);“id=add_submit”);
flag = false;
catch(Exception e)
//You can use the Logger else.
System.out.println(” EXCEPTION :”+ e.getMessage ());
}“link=Access more options”);“id=log_out”);
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 {


Hope this will help you. Please share your thoughts on this or write me at


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.