2

Here is the HTML code:

<select id="faculty_id" name="faculty_id[]" class="form-control select-select2" multiple="" tabindex="-1" style="display: none;">                                                                               
 <option value="1">Scholl Related matrial</option>
 <option value="2">English Department</option>
 <option value="3">Management  Department</option>                                          
 <option value="4">Mind Channel</option>                                            
 <option value="5">Other</option>`                                          
 <option value="6">Office Department  </option>                                 
</select>

I am new to selenium , currently am working on selenium web driver. Please suggest me some ways to click the drop down. I am creating script but did not get perfect call. Please help me to create script to click the dropdown and store the value in array.

Dropdown menu screenshot: http://prntscr.com/100j0km

Dropdown menu list: http://prntscr.com/100j1og

3
  • is it a combox when you click that field is drop down showing up ?
    – PDHide
    Feb 19, 2021 at 21:32
  • The example element you show here has 'style="display: none;"' meaning it is not visible. I think you are trying to interact with the wrong element. Feb 22, 2021 at 10:13
  • @MS Demo is trying to another method but Still Is not working. Html Code= prnt.sc/103kh9e Script code =prnt.sc/103kjb2 Console Output = prnt.sc/103kk2g Feb 22, 2021 at 10:31

1 Answer 1

1

As your element has style="display: none;" it is not displayed. Looks like the Select is an hidden container to store that data that is trigger by an INPUT element. Try setting the value of input or sending keys to the input.

Below doesnt work, because select is not interact-able:

The Selenium WebDriver has an API for working with Selects, read the working with Selects documentation here.

For Java and your situation this would look something like:

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement selectElement = wait.until(ExpectedConditions.elementToBeClickable(By.id("faculty_id")));
Select selectObject = new Select(selectElement);

selectObject.selectByIndex(1);
selectObject.selectByValue("2");
selectObject.selectByVisibleText("English Department");

Do not try to manual click the select and getting all the items. Use the API :)

10
  • Still Not working
    – MS Demo
    Feb 19, 2021 at 13:19
  • 1
    @MSDemo You get a error? "Still not working" is not a very helpfull comment to assist you resolving an issue. We cannot see your screen, so you need to provide any information that might give us a clue what is going on on your side. Feb 19, 2021 at 13:29
  • Probably the Select is not there yet when you try to access it, try waiting for it to be visible. Or it is in a HTML iFrame, try to switch to the frame first. Feb 19, 2021 at 13:30
  • I am trying to another method but Still Is not working. Html Code= prnt.sc/103kh9e Script code =prnt.sc/103kjb2 Console Output = prnt.sc/103kk2g –
    – MS Demo
    Feb 22, 2021 at 9:32
  • 1
    I got the solution, Thanks for the help.
    – MS Demo
    Feb 23, 2021 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.