簡體   English   中英

無法從 Selenium VBA 中的下拉“日期選擇器”(YYYY/MM/DD) 中選擇 select 日歷日期

[英]Unable to select calendar dates from drop down "Date selector"(YYYY/MM/DD) in Selenium VBA

嘗試使網站自動化,但我發現很難從下拉列表中選擇日期。 這是網站: https://www.icegate.gov.in/DocEnquiry/iecEnq/IECSB

我有一個 excel 文件,其中包含 IEC 代碼、PAN 編號、開始日期和結束日期。 第 2 部分我可以完成,但在選擇日期時我發現了困難。

IEC 編號

  1. 0907012248
  2. 0906018463

潘號

  1. AAFCA2804G
  2. AAGCA0259A

開始日期 - 任何 30 天范圍內。(比方說 2020/01/01 到 2020/01/31)

Sub MEISsite()

Dim bot As WebDriver
Dim count As Long

Set bot = New WebDriver
bot.Start "Chrome"
count = 1

While (Len(Range("A" & count)) > 0)

bot.Get "https://www.icegate.gov.in/DocEnquiry/iecEnq/IECSB"

bot.FindElementByXPath("//input[@id='iecNo']").SendKeys Range("A" & count)
bot.FindElementByXPath("//input[@id='panNo']").SendKeys Range("B" & count)


'Below part is where the Drop down list Date selector is causing me problem.

bot.FindElementByXPath("//tr[4]/td[2]/img[1]").Click
bot.FindElementByXPath("//select[@name='calendar-month']").SendKeys Range("C" & count)
bot.FindElementByXPath("//select[@name='calendar-year']").SendKeys Range("D" & count)

bot.FindElementByXPath("//tr[5]/td[2]/img[1]").Click
bot.FindElementByXPath("//select[@name='calendar-month']").SendKeys Range("C" & count)
bot.FindElementByXPath("//select[@name='calendar-year']").SendKeys Range("D" & count)


'bot.Wait 10000
bot.FindElementByXPath("//span[@id='iecSBEnq']").Click

Range("I" & count) = bot.FindElementByXPath("//table[@id='resultTable']").Text

'bot.Wait 1000
End If
End If
count = count + 1
Wend
bot.Quit
End Sub

我在 excel 中將年、月和日期分成單獨的列來嘗試,但是這段代碼所能做的就是單擊日期選擇器的下拉列表(僅此而已)。

請幫幫我。

可能有更好的方法,但這是我嘗試過的,對我來說沒問題

Sub MEISsite()
Dim e, bot As WebDriver, ele As SelectElement, eledpTD As Object, r As Long, i As Long

Set bot = New WebDriver
r = 1

With bot
    .Start "Chrome"

    While (Len(Range("A" & r)) > 0)
        .Get "https://www.icegate.gov.in/DocEnquiry/iecEnq/IECSB"

        .FindElementByXPath("//input[@id='iecNo']").SendKeys Range("A" & r)
        .FindElementByXPath("//input[@id='panNo']").SendKeys Range("B" & r)

        For i = 1 To 2
            With .FindElementByXPath("//*[@id='pagetable']/tbody/tr[" & i + 3 & "]/td[2]")
                .ScrollIntoView: .Click
            End With
            Set ele = .FindElementByName("calendar-month").AsSelect
            ele.SelectByIndex Month(Cells(r, i + 2)) - 1
            Set ele = .FindElementByName("calendar-year").AsSelect
            ele.SelectByValue CStr(Year(Cells(r, i + 2)))
            Set eledpTD = .FindElementsByClass("dpTD")
            For Each e In eledpTD
                If Val(e.Text) = Val(Day(Cells(r, i + 2))) Then
                    e.Click: Exit For
                End If
            Next e
        Next i

        r = r + 1
    Wend

    Stop
    .Quit
End With
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM