0

I have some code that works fine to enter data via Excel/VBA into webforms.

I have it working on other sites, but on this one site, the data is "entered" into the text box, as I can see it on screen.

But if I then click on the text box the data disappears. Likewise, if I click submit on the form, I get an error saying the text boxes are empty (even though, on screen, they are not).

As I say, the code I have works on other sites so it must be something about the site I am using.

FYI here's simplified code I am using, where IE is an Internet Explorer object:

IE.document.all("EntryField_hdn_547").Value = "My Name"

This is the URL of the form: https://public-online.hmrc.gov.uk/lc/content/xfaforms/profiles/forms.html?contentRoot=repository:///Applications/NICs_iForms/1.0/CA3822&template=CA3822.xdp

(you'll need to click through to the 3rd page, and click the "Employer" radio to see the text fields)

And this is the HTML of eg the above text entry box:

<input type="text" class="i" name="EntryField_hdn_547" tabindex="1469" aria-label="Name" style="text-align: left; vertical-align: middle; text-indent: 0px; padding: 0px 5.67px; height: 34.0157px; box-sizing: border-box; position: absolute; width: 566.93px;">

Can anyone help suggest a way to get the data to "stick" in the text boxes

(FYI I also have code to click the radio buttons, and that works fine)

Also, I tried this answer which seems very similar but still no joy: Text entered into Webpage Search Box via Excel VBA is not detected when clicking Search button

Jaspos
  • 365
  • 1
  • 4
  • 17
  • Have you tried using selenium basic? – QHarr Nov 22 '18 at 15:21
  • Not looked at that before. As I have a solution already working on other sites, I am hoping a simple tweak might get this working, rather than setting up a whole new system. – Jaspos Nov 22 '18 at 16:03
  • A lot of java script is running here. I am afraid here no simple tweak will exist and it is not possible just simply set the attribute `value` from VBA code :(. – Daniel Dušek Nov 22 '18 at 22:24

2 Answers2

2

This is dead easy with selenium basic. After install go VBE > Tools > References > Add a reference to selenium type library.

Option Explicit
Public Sub EnterInfo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const url = "https://public-online.hmrc.gov.uk/lc/content/xfaforms/profiles/forms.html?contentRoot=repository:///Applications/NICs_iForms/1.0/CA3822&template=CA3822.xdp"

    With d
        .Start "Chrome"
        .get url
        .Window.Maximize
        '.ExecuteScript "window.scrollTo(0, document.body.scrollHeight);"
        .FindElementByCss(".S").Click
        .FindElementByCss("#_hdn_30 > div._.widget.buttonfieldwidget.xfaButton").Click
        .FindElementByCss("[aria-label=employer]").Click
        .FindElementByCss("[aria-label=Name]").SendKeys "Wile E. Coyote"
        .FindElementByCss("[aria-label='Name of company']").SendKeys "Acme Corporation"
        .FindElementByCss("[aria-label='Position in company']").SendKeys "Entrepreneur"
        .FindElementByCss("[aria-label='Telephone number']").SendKeys "012345678910"
        .FindElementByCss("[tabindex='1511']").Click
        .FindElementByCss("[tabindex='1537']").Click
        .FindElementByCss("#_hdn_653 > div._.widget.buttonfieldwidget.xfaButton").Click

         Stop

        .Quit
    End With
End Sub
QHarr
  • 83,427
  • 12
  • 54
  • 101
  • 1
    Thanks QHarr - in fact, this gave me an idea, as I can use SendKeys in my code too, and that seemed to work! Selenuim looks interesting though, I will check it out when I get some time – Jaspos Nov 23 '18 at 07:36
1

QHarrs link provided the answer - by using SendKeys instead I could enter the data as text into the textboxes.

I did need to set the focus to IE first - I used the info here to get that bit sorted: Set Focus to Internet Explorer Object in Visual Basic

ie

myIE.visible = false
DoEvents
myIE.visible = true 
Jaspos
  • 365
  • 1
  • 4
  • 17