Select the time from the list and search with Selenium VBA

ptcsite46

New Member
Joined
Jan 14, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
The code is very simple, I only write the part that has the problem...



Our site: KAP ---->>>> Date Range Select 3 months range from dropbox and press the search button.



Related Web html:

Rich (BB code):
<div class="filter-singledrop mCustomScrollbar _mCS_1 mCS-autoHide mCS_no_scrollbar" style="overflow: visible;"><div id="mCSB_1" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical mCSB_outside" style= "max-height: 261px;" tabindex="0"><div id="mCSB_1_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y" style="position:relative; top:0; left:0;" dir="ltr">

                             <!---->

                                <a class="filter-singledropselect" href="#" code="0">Today</a>

                                <a class="filter-singledropselect selected" href="#" code="1">Yesterday</a>

                                 <a class="filter-singledropselect" href="#" code="30">Last 1 month</a>

                                 <a class="filter-singledropselect" href="#" code="7">Last 1 week</a>

                                 <a class="filter-singledropselect" href="#" code="90">Last 3 months</a>

                                 <a class="filter-singledropselect" href="#" code="180">Last 6 months</a>

                                 <a class="filter-singledropselect" href="#" code="365">Last 1 year</a>

                         </div></div><div id="mCSB_1_scrollbar_vertical" class="mCSB_scrollTools mCSB_1_scrollbar mCS-minimal-dark mCSB_scrollTools_vertical" style="display: none;"><div class="mCSB_draggerContainer"><div id="mCSB_1_dragger_vertical " class="mCSB_dragger" style="position: absolute; min-height: 50px; height: 0px; top: 0px;" oncontextmenu="return false;"><div class="mCSB_dragger_bar" style="line-height: 50px;"></div></div><div class="mCSB_draggerRail"></div></div> </div></div>



Excell Selenium Code:

XML:
Public Sub container()

Dim connect As New Selenium.ChromeDriver

Set connect = New Selenium.ChromeDriver

baglan.get "https://www.kap.org.tr/tr/bildirim-sorgu"

connect.Wait 1500

'Notification Submission Date Criteria

             connect.FindElementByXPath("//*[@id='email-form']/div[6]/div[1]/div[2]/div").Click

             connect.Wait 1000


'Select last 3 months

             connect.FindElementByXPath("//*[@id='email-form']/div[6]/div[1]/div[2]/div/a[5]").Click

             connect.Wait 1000


Click on the 'SEARCH Button'

connect.FindElementByXPath("//*[@id='email-form']/a[1]").Click

connect.Wait 2000

End Sub

Why doesn't this code work?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
This works for me (using Edge).

VBA Code:
Dim driver As Selenium.EdgeDriver

Public Sub Dropdown_Click_and_Search()

    Dim link1 As WebElement
    Dim link2 As WebElement
    Dim parentDiv As WebElement
    Dim searchButton As WebElement
    
    Set driver = New Selenium.EdgeDriver
    With driver
        .Start
        .Get "https://www.kap.org.tr/en/bildirim-sorgu"
    End With
    
    Set link1 = driver.FindElementByLinkText("Today")
    Set parentDiv = link1.FindElementByXPath("./..")
    parentDiv.Click
    Set link2 = parentDiv.FindElementByLinkText("Last 3 Month", 200)
    link2.Click
    Set searchButton = driver.FindElementByLinkText("Search")
    searchButton.Click
    
End Sub
For the Turkish site, which is the URL in your code, change the text strings to the Turkish equivalents.
 
Upvote 0
This works for me (using Edge).

VBA Code:
Dim driver As Selenium.EdgeDriver

Public Sub Dropdown_Click_and_Search()

    Dim link1 As WebElement
    Dim link2 As WebElement
    Dim parentDiv As WebElement
    Dim searchButton As WebElement
   
    Set driver = New Selenium.EdgeDriver
    With driver
        .Start
        .Get "https://www.kap.org.tr/en/bildirim-sorgu"
    End With
   
    Set link1 = driver.FindElementByLinkText("Today")
    Set parentDiv = link1.FindElementByXPath("./..")
    parentDiv.Click
    Set link2 = parentDiv.FindElementByLinkText("Last 3 Month", 200)
    link2.Click
    Set searchButton = driver.FindElementByLinkText("Search")
    searchButton.Click
   
End Sub
For the Turkish site, which is the URL in your code, change the text strings to the Turkish equivalents.
Perfect bro ... i am very happy , so nice
VBA Code:
Public Sub Dropdown_Click_and_Search()

    Dim driver As New Selenium.ChromeDriver

    Dim link1 As WebElement
    Dim link2 As WebElement
    Dim parentDiv As WebElement
    Dim searchButton As WebElement
    
    Set driver = New Selenium.ChromeDriver
    With driver
        .Start
        .Get "https://www.kap.org.tr/tr/bildirim-sorgu"
    End With
    
    Set link1 = driver.FindElementByLinkText("Bugün")
    Set parentDiv = link1.FindElementByXPath("./..")
    parentDiv.Click
    Set link2 = parentDiv.FindElementByLinkText("Son 3 ay", 200)
    link2.Click
    Set searchButton = driver.FindElementByLinkText("Ara")
    searchButton.Click
    
End Sub


İ convert to Chrome.. nice work... i am new in webdriver ..., what means Set parentDiv = link1.FindElementByXPath("./..") You didn't write anything in front of the parent div. i don't understan what means is this... İ am very happy i search all web but nothing like this... :))
 
Upvote 0
I integrated the code into the other macro but it gave a warning... can you take a look?

Rich (BB code):
Option Explicit
Public Sub kap_Finansal_Bildirilen3()
Dim baglan As New Selenium.ChromeDriver

Set baglan = New Selenium.ChromeDriver
baglan.get "https://www.kap.org.tr/tr/bildirim-sorgu"
baglan.Wait 1500

'Bildirim Kriterleri
'Bildirim Tipi menuye tıkla
baglan.FindElementByXPath("//*[@id='email-form']/div[4]/div[1]/isteven-multi-select/span").Click
baglan.Wait 1000
'Bildirim Tipi Finansal Raporları seç
baglan.FindElementByXPath("//*[@id='email-form']/div[4]/div[1]/isteven-multi-select/span/div/div[2]/div[2]/div/label/span").Click
baglan.Wait 1000

'Bildirim Kriterleri

'KONU Dropdown menüsüne tıkla
baglan.FindElementByXPath("//*[@id='email-form']/div[4]/div[4]/isteven-multi-select/span").Click
baglan.Wait 1000
'Bildirim Tipi Faaliyet Raporu seç
baglan.FindElementByXPath("//*[@id='email-form']/div[4]/div[4]/isteven-multi-select/span/div/div[2]/div[2]/div/label/span").Click
baglan.Mouse.Click
baglan.Wait 1000

'------------------------------------------SIKINTI ASAGIDA BASLIYOR---------------
'Bildirim Gönderim Tarihi Kriterleri
    Dim link1 As WebElement
    Dim link2 As WebElement
    Dim parentDiv As WebElement
    Dim searchButton As WebElement
    
    
    Set link1 = baglan.FindElementByLinkText("Bugün")
    Set parentDiv = link1.FindElementByXPath("./..")
    parentDiv.Click
    
    Set link2 = parentDiv.FindElementByLinkText("Son 1 ay", 200)
    link2.Click
    
    Set searchButton = baglan.FindElementByLinkText("Ara")
    searchButton.Click

End Sub
 
Upvote 0
what means Set parentDiv = link1.FindElementByXPath("./..")

In an XPath, "./" is the specified starting element, in this case link1. The XPath "./.." is its parent element, so the above code finds the link's parent (div) element. The XPath for link1's parent's parent would be "./../..".

I integrated the code into the other macro but it gave a warning... can you take a look?
Replace:
VBA Code:
baglan.Mouse.Click
with:
VBA Code:
baglan.FindElementByXPath("//*[@id='email-form']/div[4]/div[4]/isteven-multi-select/span").Click
Whick clicks the dropdown again to close it.
 
Upvote 0
i understood teacher :) thanks for your help... i works...
Do you write this code with ;

Dim XMLreq As New MSXML2.XMLHTTP60
Dim HTMLdoc As New MSHTML.HTMLDocument ?

Do you have any training videos for Excel VBA? For example Youtube , Udemy?
 
Upvote 0
I've no idea if the page could be automated with XMLhttp and HTMLDocument. You'd have to inspect the requests and responses to see what happens.

Training videos - sorry, I've never used any.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top