Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Selenium Essentials

You're reading from   Selenium Essentials Get to grips with automated web testing with the amazing power of Selenium WebDriver

Arrow left icon
Product type Book
Published in Mar 2015
Publisher
ISBN-13 9781784394332
Pages 194 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Prashanth Sams Prashanth Sams
Author Profile Icon Prashanth Sams
Prashanth Sams
Arrow right icon
View More author details
Toc

Select functions


A Select function allows you select or deselect values from a drop-down box or a radio button. It includes a list of Selenium API methods to work with select boxes that contain the <select></select> tags. These functions interact with the UI comboboxes to select options.

Select select = new Select(driver.findElement(By.locatorType("path")));

Some helpful snippets using select functions are given below:

  • The selectByIndex(index) method selects an option using the index value. The following is the syntax for this function:

    select.selectByIndex(index);

    Let's get into the bookstore and select a product from a drop-down list. Here, we select the products at the top of the options list using the selectByTndex() method:

    driver.get("http://www.barnesandnoble.com/");
    Select select = new Select(driver.findElement(By.id("quick-search-1-category")));
    select.selectByIndex(1);
    select.selectByIndex(2);
  • The selectByValue(value) method selects an option using value in the string format...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime