0

I am trying to select a time from a time picker on a website with the excel VBA code below. While the code loops through it does not select 09. What am I doing wrong? Website code also below.

Set e = appIE.document.getElementbyid("timepicker-pickup").getElementsByTagName("li")
     For Each e In e
      If e.innerHTML = "09" Then
      e.Click
      End If
    Next

Website code:

<div class="timepicker" id="timepicker-pickup">
    <div class="arrow"></div>
    <div class="icon close-btn"></div>
    <div class="inner-time-picker clearfix">
        <div class="section hours">
            <div class="up-arrow"><span class="icon arrow"></span></div>
            <div class="selectors">
                <ul>
                    <li data-value="00">00</li>
                    <li data-value="01">01</li>
                    <li data-value="02">02</li>
                    <li data-value="03">03</li>
                    <li data-value="04">04</li>
                    <li data-value="05">05</li>
                    <li data-value="06">06</li>
                    <li data-value="07">07</li>
                    <li data-value="08" class="selected">08</li>
                    <li data-value="09">09</li>
                    <li data-value="10">10</li>
                    <li data-value="11">11</li>
                </ul>
            </div>
2
  • 1
    Not sure if this will resolve your problem but it certainly not good programming practice. You are using e as your container and your object. Try using a different name for the actual object i.e. For Each i In e. You can then try i.Click Commented Oct 5, 2017 at 13:55
  • It's a definite duplicate of this thread: Link Commented Oct 5, 2017 at 18:56

2 Answers 2

2

Try this:

Dim iL as iHTMLElement
Dim e As IHTMLElementCollection

Set e = appIE.document.getElementbyid("timepicker-pickup").getElementsByTagName("li")
For Each iL In e
  If il.innerText = "09" Then
  iL.Click
  End If
Next iL
Sign up to request clarification or add additional context in comments.

9 Comments

I am receiving a Run-time error '438' Object doesn't support this property or method here: If f.innerText = "09" Then Are you able to help with what might be causing this?
type ?e.innerHTML in Immediate window and tell me what can you see.
When put this : ?e.innerHTML in the immediate window it gives a Run-time error '424' Object required.
it looks lke e wasn't initialized. You may try ?typename(e), if it is Nothing then we know that the things went wrong by: Set e = appIE.document.getElementbyid("timepicker-pickup").getElementsByTagName("li")
or depending on which line I am on it gives me the same Run-time error '438' Object doesn't support this property or method
|
1

You can use querySelector of:

appIE.document.querySelector("#timepicker-pickup *[data-value='09']").Click

No loop required.

Comments

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.