Hey guys in this post we are going to learn about how to handle simple dropdowns in Selenium Webdriver.For handling dropdowns Selenium already provides Select class that has
some predefined method which help is a lot while working with Dropdown.
In the example given below we are using select by index , select by value and select by visible dropdown text. These are three different ways by which you can select dropdown values. plus we can so some more verification on dropdowns by verifiyting selected dropdown fields and we can also fetch all the dropdown data using selenium webdriver.
Try out below code and learn how we can automate dropdown testing for anyweb application using selenium webdriver.
Video Tutorial -
import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.ui.Select; public class DropDownTest { WebDriver driver; WebElement month_dropdown; @Before public void setup() { System.setProperty("webdriver.chrome.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe"); driver=new ChromeDriver(); driver.manage().window().maximize(); driver.get("http://www.facebook.com"); month_dropdown=driver.findElement(By.id("month")); } @Test public void testSelectByIndex() { Select month=new Select(month_dropdown); month.selectByIndex(4); } @Test public void testSelectByValues() { Select month=new Select(month_dropdown); month.selectByValue("5"); } @Test public void testSelectByVisisbleField() { Select month=new Select(month_dropdown); month.selectByVisibleText("Aug"); } @Test public void testSelectedOption() { Select month=new Select(month_dropdown); WebElement first_value=month.getFirstSelectedOption(); String value=first_value.getText(); System.out.println("select dropdown value is- "+value); } @Test public void testAllDropDownOptions() { Select month=new Select(month_dropdown); List<WebElement> dropdown=month.getOptions(); for(int i=0;i<dropdown.size();i++){ String drop_down_values=dropdown.get(i).getText(); System.out.println("dropdown values are "+drop_down_values); } } @After public void teardown() { driver.quit(); } }
I really thank you for your innovative post.I have never read a creative ideas like your posts.
ReplyDeletehere after i will follow your posts which is very much help for my career.
Selenium Training in Chennai
selenium training in velachery
JAVA Training in Chennai
Python Training in Chennai
Big data training in chennai
Android Training in Chennai
Selenium Training in Chennai
Selenium Training in Anna Nagar
This was an awesome blog. The way the author has delivered the content is really simple and easy to understand. Waiting for more updates.
ReplyDeleteGerman Classes in Mulund
German Classes in Mulund West
French Classes in Mulund West
French Language Classes in Mulund
Spoken English Class in Chennai
Spoken English in Chennai
IELTS Coaching Centre in Chennai
English Speaking Course in Mumbai
IELTS Coaching in Mumbai
I would definitely thank the admin of this blog for sharing this information with us. Waiting for more updates from this blog admin.
ReplyDeletemicrosoft dynamics crm training in chennai
microsoft dynamics training in chennai
Tally Course in Chennai
ReactJS Training in Chennai
PHP Training in Chennai
ui design course in chennai
Angularjs Training in Chennai
CCNA Training in Chennai
Web Designing Course in chennai
ReplyDeleteThis content of information has
helped me a lot. It is very well explained and easy to understand.
seo training classes
seo training course
seo training institute in chennai
seo training institutes
seo courses in chennai
seo institutes in chennai
seo classes in chennai
seo training center in chennai
ReplyDeleteYou write this post very carefully I think, which is easily understandable to me. Not only this, but another post is also good. As a newbie, this info is really helpful for me. Thanks to you.
Tally ERP 9 Training
tally classes
Tally Training institute in Chennai
Tally course in Chennai
Great efforts put to publish these kinds of articles that are very useful to know. I’m thoroughly enjoying your blog. And Good comments create great relations. You’re doing an excellent job. Keep it up.
ReplyDeleteMagento Development Training Course in Chennai Zuan Education
Selenium Training Course in Chennai Zuan Education