Friday, August 26, 2016

Bootstrap Dropdown Example for Selenium

Dropdowns

The .dropdown class is used to indicate a dropdown menu.

Use the .dropdown-menu class to actually build the dropdown menu.







20 comments:

  1. if Html option is disable then how to verify in selenium that option is disabled

    ReplyDelete
  2. Sir from this below code i'm not able to print the options of dropdown

    public class DropDownOption
    {
    public WebDriver driver=new FirefoxDriver();

    public void openURL()
    {
    System.setProperty("webdriver.firefox.marionette", "D:\\Mahesh\\Library\\geckodriver-v0.14.0-win64\\geckodriver.exe");
    driver.get("http://spicejet.com");
    driver.manage().window().maximize();

    driver.findElement(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']")).click();

    List dropdown=driver.findElements(By.xpath("//div[@id='glsctl00_mainContent_ddl_originStation1_CTNR']//ul//li//a"));

    for(int i=0;i<dropdown.size();i++)
    {
    WebElement drp=dropdown.get(i);

    String innerhtml=drp.getAttribute("innerhtml");

    System.out.println("city from -- "+innerhtml);
    }
    }
    public static void main(String[] args)
    {
    DropDownOption obj=new DropDownOption();
    obj.openURL();

    }

    }

    ReplyDelete
    Replies
    1. Hi Mahesh Sheelvant

      code is correct please update,

      "innerhtml" into "innerHTML"

      String innerhtml=drp.getAttribute("innerHTML");

      Delete
  3. Thanks for Sharing this blog, it is very helpful to us. A good information to learners and each and every topic is easy to understand ...... Selenium Online Training

    ReplyDelete
  4. Excellent ! I am truly impressed that there is so much about this subject that has been revealed and you did it so nicely.
    Selenium Training in Chennai

    ReplyDelete
  5. Very nice video on bootstrap dropdown. On Ie browser, bootstrap dropdown is working using xpath but it diaappers very fast.

    How to give more time on bootstrap dropdown once it appears?

    ReplyDelete
  6. hi, it was also help ful for people working in python. I create code for python3.x and it worked 100%.
    ####Python Code Start
    from selenium import webdriver
    driver = webdriver.Firefox()
    url="http://seleniumpractise.blogspot.in/2016/08/bootstrap-dropdown-example-for-selenium.html"
    driver.get(url)
    driver.find_element_by_xpath('//*[@id="menu1"]').click()
    driver.implicitly_wait(10)
    dd_menu = driver.find_elements_by_xpath('//ul[@class="dropdown-menu"]//li/a')

    for Element in dd_menu:
    ElementValue= Element.get_attribute("innerHTML")
    print ("Value for DropDown is ------->" + ElementValue )
    if ElementValue.find('JavaScript') != -1:
    #print (ElementValue)
    Element.click()
    #### Python Code End

    ReplyDelete
  7. Thank you.Well it was nice post and very helpful information on selenium Online course Hyderabad

    ReplyDelete
  8. It Great Selinium Blogger. its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end.

    selenium Online Training Hyderabad

    ReplyDelete
  9. This is one awesome blog article. Much thanks again. selenium Online Training Bangalore

    ReplyDelete
  10. Thanks for the informative article. This is one of the best resources I have found in quite some time. Once Again Thanks for Sharing this Valuable Information i like this i Can Share this with My Friend Circle.
    Selenium Training in Noida
    Selenium Course in Noida

    ReplyDelete
  11. I really enjoy the blog.Much thanks again. Really Great selenium Online Training Bangalore

    ReplyDelete
  12. Selenium Training is one of the most powerful open source automation tool for web application testing (even we can say acceptance testing for web application) which lets you automate operations like — type, click, selection from a drop down etc of a web page. Primarily developed in Java Script and browser technologies such as DHTML and Frames and hence supports all the major browsers on all the platforms.

    ReplyDelete
  13. Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. This paragraph gives clear idea for the new viewers of blogging, Thanks you. You’re doing a great job Man, Keep it up.
    selenium Training in Delhi

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thanks for Sharing This Valuable Information with Us.
    Selenium Training in Gurgaon

    ReplyDelete