Hey there! any question in your mind? Ask It Now!.

Popular Categories

How to Handle Dynamic flex components Using Selenium Webdriver?

+4 votes
asked in Software Testing by Niks
Can anyone Help me, How to Handle Flex components that are generated runtime through Action script using Selenium WebDriver?

2 Answers

+1 vote
answered by seleniumGuru Expert (4,570 points)

Hi Niks ,

You can see procedure here to automate flex in selenium and if these components like text box or button are dynamic so you can check the pattern how these components are generating may be their ids are also generating in a particular sequence  and use for loop to create dynamic ids or give some example code which flex grid you have to automate so that I can help you better. 

commented by Niks
Below is the code snipet which dynamically generates Menu. Please guide me how will i access third menu generated by this acttion script(and id of Menucontainer on flex screen is "menuholder")

private function createMenu(value:ArrayCollection):void {
            var groupVOs:ArrayCollection = MainScreenUtil.getGroupVOs(value);
            var groupingMenuRenderers:Array = [];        
            for each (var data:Object in groupVOs) {
                var groupingMenuRenderer:GroupingMenuRenderer = new GroupingMenuRenderer();
                groupingMenuRenderer.label = data["groupCode"];
                groupingMenuRenderer.labelField = "groupName";
                groupingMenuRenderer.data = data;
                groupingMenuRenderer.children = data["children"];
            var groupingMenu:GroupingMenu = new GroupingMenu();
            groupingMenu.addEventListener(GroupingMenuEvent.MENU_CLICK, onMenuClick);
            groupingMenu.groupingMenuRenderers = groupingMenuRenderers;
            /**    var spacer : Spacer = new Spacer();
             spacer.percentHeight = 100;
            if (groupVOs.length > 0) {
                var vo : GroupVO= groupVOs.getItemAt(0) as GroupVO;           
                if (vo.children && vo.children.length > 0) {
                } else {
commented by Niks
Please suggest me solution on this.
commented by Amir
The only way to interact with Flex applications using WebDriver is by using the JavaScriptExecutor to invoke JavaScript commands
0 votes
answered by Bhartesh (2,730 points)

Use this code: 


  public String click(final String objectId, final String optionalButtonLabel) {    

    return call("doFlexClick", objectId, optionalButtonLabel);


  public String click(final String objectId) {

     return click(objectId, "");


import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

publicclass FlexWebDriver {  privatefinal WebDriver webDriver;privatefinal String flashObjectId;  public FlexWebDriver(final WebDriver webDriver, final String flashObjectId) {    this.webDriver = webDriver;

    this.flashObjectId = flashObjectId;


  public String click(final String objectId, final String optionalButtonLabel) {    return call("doFlexClick", objectId, optionalButtonLabel);


  public String click(final String objectId) {

     return click(objectId, "");


  private String call(final String functionName, final String... args) {final Object result =


         makeJsFunction(functionName, args),

         new Object[0]);

     return result != null ? result.toString() : null;


  private String makeJsFunction(final String functionName, final String... args) {

     final StringBuffer functionArgs = new StringBuffer();

    if (args.length > 0) {

      for (int i = 0; i < args.length; i++) {

        if (i > 0) {



        functionArgs.append(String.format("'%1$s'", args[i]));



    return String.format(

      "return document.%1$s.%2$s(%3$s);",







Now the example of using clicking an element :

final FirefoxDriver driver = new FirefoxDriver();

final FlexWebDriver flexDriver = new FlexWebDriver(driver, “my-application”);


 Assert.assertEquals(“true”, flexDriver.click(“aButton”));

Related Questions

+10 votes
2 answers 9,686 views
+2 votes
1 answer 216 views
0 votes
0 answers 143 views
+1 vote
1 answer 2,250 views
+2 votes
2 answers 820 views
+2 votes
1 answer 269 views
+2 votes
1 answer 104 views

Not a Member yet?

Ask to Folks Login

My Account
625 Folks are online
84 members and 541 guest online
Your feedback is highly appreciated