1

Complete my VBA code before the "EndIf" line. Please help me select the Gender from below Target Inspect HTML code . Below is my code which I have written till now. Please help to complete it.

Sub google_search()
    Dim row As Integer
    row = 2
    Dim bot As WebDriver
    Set bot = New WebDriver
    bot.Start "chrome"
    bot.Get "https://abcd.com/"     



    bot.FindElementbyName("patient_name").SendKeys "Value"
    bot.FindElementbyName("patient_id").SendKeys "Value"

    If Sheet1.Cells(row, 4) = "Years" Then
       bot.FindElementById("age_year").Click
       bot.FindElementbyName("age").SendKeys "Value"
    Else
    If Sheet1.Cells(row, 4) = "Months" Then
       bot.FindElementById("age_month").Click
       bot.FindElementbyName("age").SendKeys "Value"
    Else
    End If
    End If

    If Sheet1.Cells(row, 6) = "M" Then
    
        ...........................................................
        
    End If

 


    Stop

    End Function

Target Site as this inspect

<div class="form-group">

<label for="gender">Gender</label><span class="text-danger"><b> *</b></span>

<select name="gender" id="gender" class="form-control">

<option value="">Select Gender</option>

<option value="M">Male</option>

<option value="F">Female</option>

<option value="T">Transgender</option>

</select>

</div>

1 Answer 1

1

You are providing 2 times End If, which will throw an error. This should be your correct code.

Sub google_search()
Dim row As Integer
row = 2
Dim bot As WebDriver
Set bot = New WebDriver
bot.Start "chrome"
bot.Get "https://abcd.com/" 

bot.FindElementbyName("patient_name").SendKeys Sheet1.Cells(row, 2).Value
bot.FindElementbyName("patient_id").SendKeys Sheet1.Cells(row, 3).Value

If Sheet1.Cells(row, 4) = "Years" Then
    bot.FindElementById("age_year").Click
    bot.FindElementbyName("age").SendKeys Sheet1.Cells(row, 5).Value
ElseIf Sheet1.Cells(row, 4) = "Months" Then
    bot.FindElementById("age_month").Click
    bot.FindElementbyName("age").SendKeys Sheet1.Cells(row, 5).Value
End If


If Sheet1.Cells(row, 6) = "M" Then
    Dim GenderDD As Selenium.WebElement
    Set GenderDD=bot.FindElementById("gender")
    GenderDD.AsSelect.SelectByText(Sheet1.Cells(row, 6).value)
End If

 


Stop

End Function
Sign up to request clarification or add additional context in comments.

9 Comments

Please make focus on doted lines (just before the EndIf) .. I want to choose Gender from Excel to Web by Selenium Bot. what you said is not even an error.
Now we are focusing on the real matter, it's showing error in that specific line "Syntax Error - Compile Error" is any library cmd added in beginning codes ?
i have changed slightly as below Dim Element As Selenium.WebElement Set Element GenderDD=bot.FindElementById("gender"). check now
Compile error- Expected: = highlighting on GenderDD
here is the change Dim GenderDD As Selenium.WebElement Set GenderDD=bot.FindElementById("gender") GenderDD.AsSelect.SelectByText(Sheet1.Cells(row, 6).value)
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.