Selenium Scripts:How to check whether a list box or dropdown box allows multiple selection or not in selenium webdriver


Script 1 :-

package selenium_examples;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;



public class spicejet {

public static void main(String[] args) {


 WebDriver driver = new FirefoxDriver();

 driver.get("http://jobsearch.naukri.com/mynaukri/mn_newsmartsearch.php");

 Select droplist = new Select(driver.findElement(By.id("idqi")));

      if (droplist.isMultiple())
      {
      System.out.println("Multiple selection is allowed");
      }
   
      else
      {
      System.out.println("Multiple selection is not allowed");
      }
     
      }
  }


Output:-

Multiple selection is allowed

isMultiple() method returns TRUE if the drop-down element allows multiple selection at a time else returns FALSE.


Script 2:-

package selenium_examples;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;



public class spicejet {

public static void main(String[] args) {


 WebDriver driver = new FirefoxDriver();

 driver.get("http://book.spicejet.com/");

 Select droplist = new Select(driver.findElement(By.id("ControlGroupSearchView_AvailabilitySearchInputSearchVieworiginStation1")));

      if (droplist.isMultiple())
      {
      System.out.println("Multiple selection is allowed");
      }
            else
      {
      System.out.println("Multiple selection is not allowed");
      }
     
      }
  }

Output:-

Multiple selection is not allowed


No comments:

Related Posts Plugin for WordPress, Blogger...

Fun and Knowledge