ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ¦p¦ó¥ÎEXCEL VBA¦bCHROME¿é¤J¸ê®Æ¦A«ö¤U¬d¸ß¡H

[µo°Ý] ¦p¦ó¥ÎEXCEL VBA¦bCHROME¿é¤J¸ê®Æ¦A«ö¤U¬d¸ß¡H

½Ð±Ð¦U¦ì¤j¯«¡A§Ú·Q¥ÎVBA§ì¤½¥qºô­¶¸ê®Æ¡A¤§«e³£¬O¥ÎIE¡A»yªk¤W¤j·§¤F¸Ñ«ç»ò¼g¡A¦ý²{¦b¤½¥qIE°±¥Î¤F¡A¥u¯à¥ÎCHROME¡A§Ú¥Ø«e¥u¯à¼g¨ì¶}±ÒCHROMEºô­¶¡A¦ý¬O¦p¦ó¾Þ§@¿é¤J¼Æ¦r«ö¤U¬d¸ß¬O§¹¥þ¨S¦³ÀYºü¡Aªþ¤W¶}±ÒCHROMEªºµ{¦¡½X¥H¤ÎºI¹Ï¡AÀµ½Ð¦U¦ì¤j¯«À°¦£¸Ñ´b¡A¸U¤À·PÁ¡C
PS:¥Ñ©óµ{¦¡½X¤ºªººô§}¬O¤½¥q¤º³¡ºô­¶¡A©Ò¥H¦U¦ì¤j¯«¦b´ú¸Õªº®É­Ô¨S¿ìªk¥Ñ¥~³¡¶}±Ò¡AÁٽШ£½Ì¡C
  1. Sub test()
  2. Dim Chrome As New Selenium.ChromeDriver
  3. Dim URL As String
  4. URL = http://etrex2:8080/SelectWeb/
  5. With Chrome
  6.     .Get URL
  7. End With
  8. End Sub
½Æ»s¥N½X

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-7-9 16:40 ½s¿è

¦^´_ 1# smart3135


https://github.com/florentbr/SeleniumBasic/releases
¤U¸ü
SeleniumBasic-2.0.9.0.exe

§ó·schromeª©¥»
chrome>»¡©ú>Ãö©ógoogle chrome

¤â°Ê²Ä¤@¦¸§ó·schromedriverª©¥»
https://chromedriver.chromium.org/
¦ì¸mC:\Users\xxx\AppData\Local\SeleniumBasic\

¦w¸Ë¨Ã§ó·s«á ²Ä¤@¦¸´ú¸Õ
¶}©l>selenium Basic>Start Chome>¸õ¿ù>¦Û°Ê¦w¸Ë.net fromework>­«¶}¾÷

²Ä¤G¦¸´ú¸Õ
¶}©l>selenium Basic>Start Chome>click ok to quit




«á´Á¤Þ¥Î¼gªk(ÁקK´«¹q¸£ÁÙ­n­«³])
set driver = CreateObject("Selenium.ChromeDriver")

¾Þ§@¾Ç²ß°Ñ¦Òºô§}
https://club.excelhome.net/thread-1452021-1-1.html









¦Û°Ê§ó·schromedriver  vba¥N½X(³q±`¤@­Ó¤ë¥ª¥kgoogle·|§ó·sÂsÄý¾¹¤@¦¸)
Sub seleniumOPEN()

'§Q¥Îerror¤è¦¡§PÂ_selenium¬O§_²§±` ­Y¦³²§±`err´N¤£¬O0  ´N·|¶i¤J updataSelenium ªºµ{§Ç§ì¨ú·sªºchromedriveª©¥»
Do
    On Error GoTo 0
    On Error Resume Next
    Set driver = CreateObject("Selenium.ChromeDriver")
    Err = 0
    driver.Get "https://www.google.com.tw"   '¤@©w­n¥[https:// ¤£µM·|¥X²{¯«©_ªº²§±`²{¶H
    If Err <> 0 Then
            driver.Quit
            Set driver = Nothing
            Call updataSelenium
    End If
Loop Until Err = 0

msgbox "§¹¦¨"
End Sub


Sub updataSelenium()
'¥ý§PÂ_chromedriver¦b­þ­Ó¸ê®Æ§¨
path1 = "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\Chromedriver.exe"
path2 = "C:\Program Files\SeleniumBasic\Chromedriver.exe"
If Dir(path1) <> "" Then TempDrvFile = path1
    'Kill (TempDrvFile)  '°²¦p¦b¿ù»~ªº±¡ªp¤U §ä¨ì¤FÀÉ®× ¨º¤§«á±N­n§ó·s½Æ»sÂл\ ÁקK¸õ¥X½Æ»s¤w¦s¦b¿ù»~ĵ§i ©Ò¥H¥ý§R°£±¼
If Dir(path2) <> "" Then TempDrvFile = path2

'§PÂ_chromeªºª©¥»¸¹
Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")  'Get chrome version
chrversion = CreateObject("WScript.Shell").RegRead("HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon\version")
dotsarr = Split(chrversion, ".")
leftchrver = dotsarr(0) & dotsarr(1)

'§PÂ_chromedriverª©¥»¸¹
Set oShell = CreateObject("wscript.shell")
errcode = oShell.Exec(path1 & " --version").StdOut.ReadAll
verarr = Split(errcode, " ")
chrdrv = verarr(1)
dotsarr2 = Split(chrdrv, ".")
leftchrdrv = dotsarr2(0) & dotsarr2(1)
If leftchrver = leftchrdrv Then Exit Sub '§Q¥Îª©¥»¸¹ªº«e¨â¦ì§PÂ_¬O§_¦Pª©¥»


'§Q¥Îª©¥»¸¹²Ä¤@¦ì ¤W©xºô¬d¸ß ·í«eª©¥»ªº³Ì²×ª©¥»¸¹
URL = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE_" & dotsarr(0)
Call objHttp.Open("GET", URL, False)
Call objHttp.Send("")
version_number = objHttp.responseText
dotsarr3 = Split(version_number, ".")
leftversion_no = dotsarr3(0) & dotsarr3(1)
download_url = "https://chromedriver.storage.googleapis.com/" + version_number + "/chromedriver_win32.zip"
   
    '§Q¥Î¨ú±oªºª©¥»¸¹ ¨ú±o¤U¸üºô§} ¨Ã¶}±Òchromedriver.zip¤U¸ü­¶­±
    Call objHttp.Open("GET", download_url, False)
    Call objHttp.Send("")
        
        '¶}±Òadodb±µ¦¬¤U¸üÀ£ÁYÀÉ ¨Ã©ñ¤Jseleniumªº¸ê®Æ§¨
        Set fileStream = CreateObject("ADODB.Stream")
        With fileStream
            .Open
            .Type = 1 'adTypeBinary
            .Write objHttp.responseBody
            .Position = 0
            .SaveToFile "C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\chromedriver.zip", 2  'adSaveCreateOverWrite 'adSaveCreateOverWrite
            .Close
        End With
        
        '¸ÑÀ£ÁY ·|¥ý±Nª©ªº§R°£ ¤~¸ÑÀ£ÁY
        Set oApp = CreateObject("Shell.Application")
        If Dir(path1) <> "" Then Kill path1
        oApp.Namespace("C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\").CopyHere _
            oApp.Namespace("C:\Users\" & Environ$("username") & "\AppData\Local\SeleniumBasic\chromedriver.zip").Items


'¥þ³¡§¹¦¨«á ·|¦^¨ì¤W¤@­Ósub ¨Ã­«·s§PÂ_¬O§_ª©¥»¿ù»~
End Sub

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-7-9 18:09 ½s¿è

¦^´_ 1# smart3135


»Ý­nªþ¤W ¨º¨â­Ó¤¸¥óªº¬ÛÃö¸ê°T  ¨Ò¦pID  class  tagname   
     
­n¦bÂsÄý¾¹«öF12  ¨Ã¦b·Q¬dªº¤¸¥ó¤W­±         ¥kÁä  >Àˬd (­«½Æ2¦¸)

¤×¨ä¬O¬Y¨Ç¤º³¡ºô­¶Âîج[ ´Nºâ¤W­z §A¦³µ¹

¤]¥i¯à¦]¬°iframe¤£¦P®Ø¬[ µLªk¥Î  ¦ý¥i¥H¥ý¸Õ¸Õ

¥t¥~¸É¥R ¦³ID²³æ¤@ÂI
¨SID ´N­n¶¶µÛ ¯ª®]¶¥¼h ®i¶}¥þ§ì

TOP

¦^´_  smart3135


https://github.com/florentbr/SeleniumBasic/releases
¤U¸ü
SeleniumBasic-2.0.9 ...
singo1232001 µoªí©ó 2022-7-9 16:39


·PÁ±z´£¨Ñªº³o¨Ç¸ê°T¡A·|¦A¦n¦n®ø¤Æ¤@¤U¡C

TOP

¥»©«³Ì«á¥Ñ smart3135 ©ó 2022-7-10 00:32 ½s¿è
¦^´_  smart3135


»Ý­nªþ¤W ¨º¨â­Ó¤¸¥óªº¬ÛÃö¸ê°T  ¨Ò¦pID  class  tagname   
     
­n¦bÂsÄý¾¹«öF ...
singo1232001 µoªí©ó 2022-7-9 18:05

±z¦n¡A­ì¨Ó§Ú¤@¶}©l´N·d¿ù¤F¡A¤£¬O¦bºô­¶«ö¥kÁä¿ïÀˬdºô­¶­ì©l½X¡A¦Ó¬O­n«öF12¬d¤¸¥ó¡A«á¨Ó¦³¸ß°Ý¨ì¡AÀ³¸Ó¬O­n¥Î.FindElementById¡B.FindElementByName¡B.FindElementByXPathªº»yªk¡A¦p¤U­±¥ÎYahoo©_¼¯­º­¶·j´Mªº¨Ò¤l
  1. Sub test()
  2.     Dim chrome As New Selenium.ChromeDriver, UrL As String, s  As String
  3.     UrL = "https://tw.yahoo.com/"
  4.     s = "§¿¥¬"
  5.         With chrome
  6.         .Get UrL
  7.         .FindElementById("header-search-input").SendKeys (s)
  8.         .FindElementById("header-desktop-search-button").Click
  9.        End With
  10.      Stop
  11.      chrome.Quit
  12.     Set chrome = Nothing
  13.     End Sub
½Æ»s¥N½X
¥H©_¼¯³o­Ócase¨Ó»¡¡A¤¸¥ó¬O¥ÎID¡A©Ò¥H¬O¥Î.FindElementById¡A¤U¶g¨ì¤½¥q·|¦A¥ÎF12¬d¸ß¤@¦¸¤¸¥óªº¬ÛÃö¸ê°T¦Aªþ¤W¹Ï¤ù¡A¦b¦¹¤§«e¦³´X­ÓºÃ°Ý·Q¥ý½Ð±Ð±z
1.¦b©_¼¯­º­¶¡A§Ú«ö¤UF12¡A¤@¶}©l¨Ã¨S¿ìªk§ä¨ì"header-search-input"©M"header-desktop-search-button"³o¨â­ÓÃöÁäµü¡A¬Oµ¥«ö¤UCrl+F·j´M®Ø¥X²{«ákey¤Jsearch«á¤~¥X²{¡A¤£¤Ó²z¸Ñ¬°¤°»ò­n¦b³o¼Ë¾Þ§@«á¤~·|¥X²{ÃöÁäµü¡A§Ú³o¼Ëªº§@ªk¬O¥¿½Tªº¶Ü¡H©Î¬O¦³¨ä¥L¤ñ¸û¥¿½Tªº¤èªk¥i¥H¬d¨ì"header-search-input"©M"header-desktop-search-button"³o¨â­ÓÃöÁäµü¡H

2.±z»¡¦b·Q¬dªº¤¸¥ó¤W­±         ¥kÁä  >Àˬd (­«½Æ2¦¸)¡A³o¸Ì¤£¬O«ÜÀ´¡A¥i¥H¦A¸Ô­z¤@¤U©Î¬O´£¨Ñ°Ñ¦Ò¹Ï¤ù¶Ü¡H
¥ý·PÁ±zªº«ü¾É

TOP

¦^´_ 5# smart3135


    ¦b¤¸¥ó¤W Àˬd¨â¦¸ ¤~·|¥þ®i¶}

    ²Ä¤@¦¸¥u·|¿ï¾Ü¨ì¤¸¥óªº¤W¼h©ÎªÌ®Ø¬[
    ²Ä¤G¦¸¤~·|¦Û°Ê¸õ¨ì¤¸¥ó¥»¨­

TOP

¦^´_  smart3135


    ¦b¤¸¥ó¤W Àˬd¨â¦¸ ¤~·|¥þ®i¶}

    ²Ä¤@¦¸¥u·|¿ï¾Ü¨ì¤¸¥óªº¤W¼h©ÎªÌ®Ø¬[
   ...
singo1232001 µoªí©ó 2022-7-10 01:30

¥i¥H¦A©M±z½T»{¤@¤U¶Ü¡H¬O¥ªÁä¨â¦¸ÁÙ¬O¥kÁä¨â¦¸¡H§Ú«ö¥kÁä·|¥X²{¹Ï¤¤¬õ®Øªºµøµ¡¡C

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2022-7-11 03:58 ½s¿è

¦^´_ 7# smart3135


¨ä¹ê¥i¥H¤£¥Î«öF12

(¥kÁä>Àˬd)°µ¨â¦¸    ¤£¬O¥kÃ䪺¬õ®Ø,¦Ó¬O¥ªÃ䪺Åã¥Üµe­±¤Wª½±µ¾Þ§@

¤¤¤åª©ªº¬O"Àˬd"  ­^¤åª©ªº§Ú§Ñ¤F




­Yµe­±¦³«ÊÂê  ´N­n¥ýF12 µM«á¥kÃ䪺µ{¦¡½X  ¥Î·Æ¹«¤W¤U²¾°Ê  ¬Ý¥ªÃäµe­±­þ¸Ì³Q®Ø°_¨Ó ´N¯à³vº¥§ä¨ì

©ÎªÌ¦w¸Ëgoogle chrome°Ó©±ªº Selenium IDE ÂX¥R¥\¯à ¨Ó§ì(¹J¨ìÂëܲ`ªº¤~»Ý­n)

¤ñ¦p§A»¡ªº¨º­Ó·j´MÄæ´N¬O
chrome.FindElementById("header-search-input").clear
chrome.FindElementById("header-search-input").sendkey "ÃöÁä¦r"
ÂIÀ»¬d¸ß«ö¶s
chrome.FindElementById("header-desktop-search-button").click





1.¥t¥~«Øij ¦b½s¼g¹Lµ{ ¤d¸U¤£­n¥Îwith ªº¼gªk ³o·|³y¦¨§A´ú¸Õ³Â·Ð
2.ID³q±`¥u¦³1­Ó ©Ò¥H«Ü¦n¤Ö
3.«DIDªº¤¸¥ó ³q±`¤£¥u1­Ó  ´N¥i¥H+s
¨Ò¦p:
set tag1 = chrome.FindElementByTag("input")   ³o­¶­±¦Ü¤Ö¶W¹L10­Ó¥H¤W
´N¸Ó§ï¦¨
set tag1 = chrome.FindElementsByTag("input")

³o¼Ë´N¯à¦b¤§«á§â©Ò¦³ªºinput ³£©ñ¤J tag1 ¤º ¨Ã¹³°}¦Cª«¥ó¤@¼Ë ·|¦Û°Ê½s¸¹

¤§«á´N¥i¥H³æ¿W¿ï¾Ü
tag1(0)
tag1(1)
.
.
.
.
.
tag1(tag1.count) ¤ºªºªF¦è¤F





¸É¥R
­n¤£­nset ´N¬Ý§A¤§«áÁÙ­n¤£­nÄ~Äò¥Î
¦p¤W­z¨Ò¤l
chrome.FindElementById("header-search-input").clear
chrome.FindElementById("header-search-input").sendkey "ÃöÁä¦r"
·í¤Usendkey ©ÎªÌclick ´N¨S¥²­nÃB¥~set
·íµM ¤]¥i¥H
set id1 = chrome.FindElementById("header-search-input")
id1.clear
id1.sendkey "ÃöÁä¦r"

TOP

¥»©«³Ì«á¥Ñ quickfixer ©ó 2022-7-11 05:51 ½s¿è

¦^´_ 8# singo1232001


    1.¥t¥~«Øij ¦b½s¼g¹Lµ{ ¤d¸U¤£­n¥Îwith ªº¼gªk ³o·|³y¦¨§A´ú¸Õ³Â·Ð

¬Ý¼Ó¥Dªºµ{¦¡½X,¥Îwithµ²ºcº}«G,¤]¥u¥Î¤F1­Ó,¤£·|¦³°ÝÃD
§Úgoogle¨ì¥Îwith¥u¦³¦n³B
§Ú¤£¹³§A³o»òºë³qµ{¦¡,·d¤£²M·¡³o´X¦æµ{¦¡½X·|¥X¤°»ò°ÝÃD
½Ð±Ð¤@¤U³oºØwith¼gªk·|¥X²{¤°»ò³Â·Ð?


https://docs.microsoft.com/zh-tw/dotnet/visual-basic/language-reference/statements/with-end-with-statement
¦pªG±zªºµ{¦¡½X·|¦b¦h­Ó³¯­z¦¡¤¤¦s¨ú¬Û¦Pª«¥ó¡A¨Ï¥Î With ³¯­z¦¡¦³¤U¦C¦n³B¡G

±z¤£»Ý­n¦h¦¸µû¦ô½ÆÂøªº¹Bºâ¦¡©Î«ü¬£µ²ªGµ¹¼È¦sÅܼơA¥H¦h¦¸°Ñ¦Ò¨ä¦¨­û¡C

±z¥i¥HÅýµ{¦¡½X§ó®e©öŪ¨ú¡A¤èªk¬O±Æ°£­«½Æªº­­©w¹Bºâ¦¡¡C

TOP

¦^´_  smart3135


¨ä¹ê¥i¥H¤£¥Î«öF12

(¥kÁä>Àˬd)°µ¨â¦¸    ¤£¬O¥kÃ䪺¬õ®Ø,¦Ó¬O¥ªÃ䪺Åã¥Üµe­± ...
singo1232001 µoªí©ó 2022-7-11 03:43

±z¦n¡A¤µ¤Ñ¨ì¤½¥q¥Î¤F·Æ¹«¥kÁä¿ïÀˬd¡A¯uªº¯à§ä¨ì¹ïÀ³ªº¤¸¥ó¤º®e¡A¥u¬OÁÙ¬O¤£¬O«Ü²M·¡³o­ÓFindElement¸Ó«ç»ò¼g¡A¥i§_¦A³Â·Ð±zÀ°¦£¬Ý¤@¤U¡A­YÁٻݭn¨ä¥L¸ê°T½Ð¦A§iª¾¡A«D±`·PÁ±z¡C

1.­º¥ý²{¦bSearchÂI¤@¤U



2.¦b½Ð¿é¤J¤u³æ¸¹½XÄæ¦ì¿é¤J¤u³æ¸¹½X


3.«ö¤U¬d¸ß§Y¥i±o¨ìµ²ªG

TOP

        ÀR«ä¦Û¦b : ¤@­Ó¯Ê¤fªºªM¤l¡A¦pªG´«¤@­Ó¨¤«×¬Ý¥¦¡A¥¦¤´µM¬O¶êªº¡C
ªð¦^¦Cªí ¤W¤@¥DÃD