How to select Gender from Dropdown list using Excel VBA?

YJones

New Member
Joined
Jul 14, 2023
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
I'm stuck with
how to select the Gender (Male / Female) from a dropdown list in a Website. My current script works, apart for the gender part:

VBA Code:
Sub MERF()

  Dim IE As Object
  Dim doc As HTMLDocument
  Set IE = CreateObject("InternetExplorer.Application")
  
  IE.Visible = True
  IE.navigate "https://portal.spsc.gov.sa/MEH/Default.aspx?Id=386"
  
  Do While IE.Busy
     Application.Wait DateAdd("s", 1, Now)
  Loop
  
  Set doc = IE.document

  'IE.document.getElementById("ContentPlaceHolder1_Mr_Txt").Value = "very cute"
  doc.getElementById("ContentPlaceHolder1_Event_Date_Txt").Value = Sheet1.Range("F34").Value
  doc.getElementById("ContentPlaceHolder1_Wasfaty_Chk_1").Click
  Application.Wait Now() + TimeValue("00:00:05")
  doc.getElementById("ContentPlaceHolder1_Wasfaty_Other").Value = Sheet1.Range("T34").Value
  doc.getElementById("ContentPlaceHolder1_Mr_Txt").Value = Sheet1.Range("B34").Value
  doc.getElementById("select2-ContentPlaceHolder1_Gender_Drop-container").Click
  doc.getElementById("ContentPlaceHolder1_Event_Desc_Txt").Value = Sheet1.Range("M34").Value
  doc.getElementById("ContentPlaceHolder1_txtReporterComment").Value = Sheet1.Range("Q34").Value
  doc.getElementById("ContentPlaceHolder1_Reporter_Name_Txt").Value = "name"
  doc.getElementById("ContentPlaceHolder1_Reporter_Email_Txt").Value = "mail"
  doc.getElementById("ContentPlaceHolder1_Reporter_Mobile_Txt").Value = "xxxx"

  
End Sub

It blocks in this line:
doc.getElementById("select2-ContentPlaceHolder1_Gender_Drop-container").Click


I tried GetElementByID and GetElementByClassName for the Gender field but it does not work. I added a value Male, but it doesn't want to appear in the text field, even after adding Click.

Any help would be much appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top