0

I am trying to select 09 from the time picker below using excel VBA. I have got as far as the line below but do not know how to proceed. Any assistance would be greatly appreciated.

Set e = appIE.document.getElementbyid("timepicker-pickup")


<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>
                <div class="down-arrow"><span class="icon arrow"></span></div>
3
  • Can you also give the sweb site you are trying to scrap? Commented Oct 4, 2017 at 8:11
  • 2
    @Vityata europcar.co.za Commented Oct 4, 2017 at 8:15
  • Have a look at this: stackoverflow.com/questions/41688620/… Commented Oct 4, 2017 at 8:59

1 Answer 1

1

CSS selectors:

Try selector #timepicker-pickup li:nth-child(10)

appIE.document.querySelector("#timepicker-pickup li:nth-child(10)").Click

The # means className and so selects the 10th li tag within element with className timepicker-pickup

or selector #timepicker-pickup [data-value='09']

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

This is simply an abbreviation where I look for anything with attribute data-value='09' within the className of timepicker-pickup

I tested with the latest which works.


CSS selector:

CSS query


VBA code:

Public Sub test()
    Dim ieApp As InternetExplorer, URL As String

    URL = "https://www.europcar.co.za/"
    Set ieApp = New InternetExplorer

    With ieApp
        .Visible = True
        .navigate URL
        While .Busy Or .readyState < 4: DoEvents: Wend

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

        Stop '<== Delete me
        '.Quit <'== Uncomment me
    End With
End Sub
Sign up to request clarification or add additional context in comments.

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.