Last active
May 14, 2021 17:52
-
-
Save dck-jp/9049627 to your computer and use it in GitHub Desktop.
sample code of Selenium-VBA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Explicit | |
Private driver As SeleniumWrapper.WebDriver | |
Private Sub InitializeWebDriver() | |
Set driver = New SeleniumWrapper.WebDriver | |
Call driver.Start("firefox", "http://192.168.1.1/") | |
End sub | |
Private Sub Login() | |
'ログイン画面 | |
driver.get ("/Default.aspx") | |
driver.findElementById("LoginId_TBox").Clear | |
driver.findElementById("LoginId_TBox").SendKeys "username" | |
driver.findElementById("Pass_TBox").Clear | |
driver.findElementById("Pass_TBox").SendKeys "pass" | |
driver.findElementById("Login_Btn").Click | |
End Sub | |
Private Sub Search(ourRef As String) | |
'簡易検索画面 | |
Call driver.get("/Search.aspx") | |
Call driver.findElementById("MainContent_Ref_TBox").Clear | |
Call driver.findElementById("MainContent_Ref_TBox").SendKeys(ourRef) | |
Call driver.findElementById("MainContent_Search_Btn").Click | |
End Sub | |
Public Function GetText(ourRef As String) | |
Call InitializeWebDriver | |
Call Login | |
Call Search(ourRef) | |
Dim id: id = driver.findElementById("MainContent_OurRef_Link").getAttribute("href") | |
' 基本情報画面 | |
Call driver.get("/OurRefInfo.aspx?id=" & id) | |
GetText = driver.findElementByCssSelector("#InfoContent_MainInfo > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2)").text | |
End Sub |
FYI, there is also an alternative to Selenium VBA, for those that might have issues with it: http://htejera.users.sourceforge.net/vbswebdriver/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have noticed the same problem as CatchColt and NoviceDJ.
I am using Firefox 46 version. Any clues??