VBA code required for Excel to populate web form using Selenium and Google Chrome

Viewed 68

Can someone help me please? I've re-written my ask to make it easier to understand.

I am using Excel VBA and trying to populate a web form and click "submit" using selenium.

I have the VBA code for opening the website which works fine (copied below).

I've spent 3 days searching the internet for how to do this and I haven't found anything tha works so far.

What I am hoping someone on here could help me with, is the code I need to add to the VBA script to;

1.Insert the text from sheet rawdata (cell B1) in to the webpage box named "subject"

2.Insert the text from sheet rawdata (cell C1) in to the webpage box named "messagetext"

  1. Click on button (type = "submit") value="Send message" in the webpage.

Here's the VBA code I currently have which successfully opens the webpage in a Chrome broswer.

Option Explicit

Sub openurl()


Dim ChromeLocation As String
Dim MyURL As String
Dim i As Integer
Dim ws1 As Worksheet
Dim lastRow As Long

Range("A1").Select

lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

Set ws1 = Sheets("rawdata")

ChromeLocation = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" 'Location of 
Chrome.exe in your PC

For i = 1 To lastRow

MyURL = ws1.Cells(i, 1)

    Shell (ChromeLocation & " -url -newtab " & MyURL)


 ' I want to insert code here to be able to enter text from cell B1 in sheet "rawdata" and 
enter it in to the subject box on the web page

 ' I want to insert code here to be able to enter text from cell C1 in sheet "rawdata" and 
enter it in to the messagetext box on the web page

  ' I want to insert code here to be able to click on the button "Sendmessage" to submit the form.


Next i

End Sub

Here's the HTML from the website with the relevant lines of code for "subject", "messagetext" and the Submit button.

" Subject: "
<input type="text" name="subject" value="">
<p></p>


<textarea style="font-family: 'Helvetica Neue',arial,sans-serif; font-size: 13pt; color: 
black; width: 90%; max-width: 600px" rows="10" cols="50" name="messagetext"></textarea>
<p></p>


<input type="submit" value="Send message">

Any advice will be gratefully received as I'm a novice at VBA and have learnt all of this over the last 4 days and I've now hit a brick wall.

Thank you

Mark

0 Answers
Related