none
auto-login in chrome using selenium vba RRS feed

  • Question

  • Hello,

    I would like to use vba to access a web site and perform other operation once logged in, but i have problem with log in. When I run the code below I have a error 438 - Object doesn't support this property or method.

    I precise that I am trying to browse Chrome because it is faster and I have problems with IE. So i downloaded Selenium.

    Plase help me find how to correctly enter my id and password in this website. Thank you very much for you help

    Sub testchrome()

    Dim obj As New WebDriver

    Dim Keys As New Keys

    obj.Start "chrome"
    obj.Get "https://freebitcoin.io"

    obj.FindElementsByClassName("form-control email").SendKeys ("xxxx@outlook.com")

    Friday, September 13, 2019 8:30 PM

All replies

  • I use XPath to select elements.  There are 3 email and 2 passwords on page.  You need to specify which one you want.

    Dim text As String
    Dim ele As Selenium.WebElement
    Dim drv As Selenium.ChromeDriver
    
    Sub Login()
       '' Add reference to selenium type library
      Set drv = New Selenium.ChromeDriver
      Dim xPath As String
      Dim browser As String
    
      drv.Get "https://freebitcoin.io"
      xPath = "//input[@name='email'][1]"
      If GetElement(xPath) Then
        ele.SendKeys "myUserId"
        xPath = "//input[@name='password'][1]"
        If GetElement(xPath) Then
          ele.SendKeys "myPassword"
          xPath = "//button[contains(@class, 'login')]"
          If GetElementClick(xPath) Then
            drv.Wait (3000)
            drv.Window.SetSize 1200, 1000
            drv.Window.SetPosition 0, 0
            browser = drv.Manage.Capabilities.Get("browserName", 0)
          End If
        End If
      End If
    End Sub
    
    Function GetElement(xPath As String) As Boolean
      On Error GoTo Handler
      
      text = ""
      Set ele = drv.FindElementByXPath(xPath)
      text = ele.text
      GetElement = True
      Exit Function
    Handler:
      Err.Clear
      GetElement = False
    End Function
    
    Function GetElementClick(xPath As String) As Boolean
      On Error GoTo Handler
      
      text = ""
      Set ele = drv.FindElementByXPath(xPath)
      ele.Click
      drv.Wait (1000)
      GetElementClick = True
      Exit Function
    Handler:
      Err.Clear
      GetElementClick = False
    End Function
    
    

    Saturday, September 14, 2019 11:22 PM