Showing posts with label Actionbuilder. Show all posts
Showing posts with label Actionbuilder. Show all posts

Sunday, June 16, 2013

Selection multiple options from Drop-down with Checkbox List

In Continuation of the Drop-down topic that i have written earlier ( Click to read) , i forget to mention one more kind of Drop-down  as given below :-


 This works as follow   , on clicking All residential Properties , a drop down will appear with multiple checkbox to select . user can select Multiple option at a time from this Checkbox list . The Concept for this is again same

Click on Main element , wait for subelement to appear on the screen and click on submenu one by one using ActionBuilder Class. Let's come to code

    Actions action = new Actions(driver);
    WebElement mainDropdownElement = driver.findElement(By.id("proptypecheck")); // main Element
    WebElement subElement1 = driver.findElement(By.id("ptypecheck_5")); // Sub Element 1
    WebElement SubElement2 = driver.findElement(By.id("ptypecheck_8")); // SubElement 2
    /* Action_one basically dealing with clicking main Element and action after that is clicking on Checkboxex one by one */   
    Action action_one = action.click(mainDropdownElement).build();
    action_one.perform();
    Thread.sleep(2000);   
     action.click(subElement1).click(SubElement2).build().perform()    ;

Hope that Helped ....






Saturday, June 15, 2013

Selecting Multiple Option at a time from a List

One of the Scenario that is less frequent but comes in picture sometime is when we have to select
a Multiple options from a list Box  e.g. you are applying for a job and you have to select Domain in which you are working such as Finance , Retail etc . The below screen will give you an idea



So lets start the Coding for the same . This can be done very easily using the AdvancedUserInteractions
You can read a lot about them Here
We will be using some KeyBoard Actions  ( We have to hold CONTROL key and then Click on options which we want to select ) , so the same can  be done using ActionBuilders in webdriver.Lets take a look at
the sample code for the same scenario

        Actions builder = new Actions(driver);
        WebElement option1 = driver.findElement(By.id("m_opt_0"));

        WebElement option2 =driver.findElement(By.id("m_opt_3"));
        builder.keyDown(Keys.CONTROL).click(option1).click(option2).keyUp(Keys.CONTROL);
        Action select_multiple = builder.build();
        select_multiple.perform();

what the Hell above code is doing ??

1) Its saving both the Options you want to select in a webElement Object .
2) Using Actionbuilder its Pressing CONTROL Key , and then Clicking option1 object and subsequently Option2 element .

Hope that Helped.