Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9080465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:04:51+00:00 2026-06-16T20:04:51+00:00

I want to select options under particular optgroup from a multiselect picklist field, for

  • 0

I want to select options under particular optgroup from a multiselect picklist field, for example

<select id="xyz">
   <optgroup label="Group1">
      <option value="1">pick1</option>
      <option value="2">pick2</option>
   </optgroup>
   <optgroup label="Group2">
       <option value="3">pick3</option>
       <option value="4">pick4</option>
   </optgroup>
</select>

if the picklist field is like above, I can use

new Select(driver.findElement(By.id("xyz"))).selectByVisibleText("pick1");
new Select(driver.findElement(By.id("xyz"))).selectByVisibleText("pick2"); 

for selecting all the options which is under optgroup -Group1 from the above.

Here I know which are all the options present in the Group1 and hence I can select like above.

But my requirement is dynamically I need to select all the options under optgroup-Group1.

If I want to select all the options both including Group 1 & 2 dynamically

Then I can use

new Select(driver.findElement(By.id("xyz"))).getOptions();

to get all options as a List and I can store it as an array, and I can select all the Options one by one using array

But how can I get all the options under only one specific optgroup say Group1 or Group2?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:04:52+00:00Added an answer on June 16, 2026 at 8:04 pm

    You should use xpath and findElements:

    driver.findElements(By.xpath("xpath = "//select[@id='xyz']/optgroup[@label='Group1']/option")))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two select option field. <div style=float:left; width:7%> <label>Type</label> <select name=ostatus id=ostatus class=input-small>
In select.phtml under /template/bundle/catalog/product/view/options/type/bundle/option/select.phtml it has the function for creating options for the select
i have a html select with options in my views . onchange i want
I've a jQuery UI autocomplete dropdown, I want to select one of the options,
When user clicks on select box , I want to hide the options menu
I'm trying to style a select option list using CSS. I want more padding
I want the user to be able to select an option, which would change
I have a form and I want to add a select location option. How
I don't want the text of the selected option in my select box to
I want a combobox by default selected the last option (using jquery): <select> <option>item1</option>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.