­

Subscribe

About Me

My photo
Welcome to my corner of the internet! I’m a software engineer by day, mechanical engineer by degree, some-time traveler, music lover, and self-proclaimed motivational speaker by... well, any spare minute I can find. When I’m not busy debugging code, you can find me lost in a new place, jamming to a mix of Indian and Western music (yes, I’m the one who creates playlists that make no sense), or pondering the mysteries of the universe, from physics to geopolitics. Oh, and if you need some motivation or a good laugh, I’m your go-to person—I'm basically a walking TED talk. Stick around for random musings, technical rants, and possibly some okayish poetry ✍️!

Translate

Wednesday, February 12, 2025

Selenium Webdriver (Part 3) - Dropdown

 static dropdown


- works only for dropdowns having web element with select as tagName.

WebElement staticdropdown = driver.findElement(By.id("")); 
Select dropdown = new Select(staticdropdown);
dropdown.selectByIndex(3);
dropdown.selectByValue("XYZ");
dropdown.selectByVisibleText("XYZ");
dropdown.getFirstSelectedOption().getText()

 dynamic dropdown

// parent - child relationship xpath; comment one of the two

Here one location can be in both From and TO dropdowns so we need to consider the From and TO Weblocators as parents and then
add the location as child.
Example below:

driver.findElement(By.xpath("//div[@id='ctl00_mainContent_ddl_originStation1_CTNR'] //a[@value='BLR']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//div[@id='ctl00_mainContent_ddl_destinationStation1_CTNR'] //a[@value='MAA']")).click();

ctl00_mainContent_ddl_originStation1_CTNR - From locaton dropdown
ctl00_mainContent_ddl_destinationStation1_CTNR - To location dropdown







No comments:

Post a Comment

Persistent Automation Testing Interview Questions (5+ YOE)

What is Serialization and Deserialization and how to perform it? WAP for changing d to D in "I am from India" WAP for counting no....