title: How to target CSS button elements properly with VBA Selenium when they don't have any IDs?
body: <p>I am trying to target and click a button on a site that requires me to open up a dropdown menu, select the option on the list, and click Apply. I have gotten it most of the way there but I can't seem to get it to click the button. Here is a link to the relevant HTML that I am working with <a href="https://pastebin.com/n5hJY3ua" rel="nofollow noreferrer">https://pastebin.com/n5hJY3ua</a>. And the full Xpath of the button is: /html/body/div[5]/div[3]/div/button[1]</p>
  
  <p>I have tried various ways to target the button such as:</p>
  
  <pre><code>.FindElementByXPath("//div[@button='Apply']").Click
  
  .FindElementByClass("applyBtn btn btn-small btn-success").Click
  
  .FindElementByXPath(".//div[@button, 'Apply']").Click
  </code></pre>
  
  <hr>
  
  <pre><code>Option Explicit
  
  Public Sub ClickDate()
      Dim t As Date
      Dim ele As Object
      Dim driver As New ChromeDriver
      Dim post As WebElement
      Dim i As Integer
      Dim mysheet As Worksheet        
  
      Const MAX_WAIT_SEC As Long = 10
      Const INURL = "https://ss3.shipstation.com/#/dashboard"
      Const URL = "https://ss3.shipstation.com/"
  
      Set mysheet = Sheets("Sheet1")
  
      With driver '&lt;==log into shipstation
          .Start "Chrome"
          .get URL
          t = Timer
          Do
              On Error Resume Next
              Set ele = .FindElementById("username")
              On Error GoTo 0
              If Timer - t &gt; MAX_WAIT_SEC Then Exit Do
          Loop While ele Is Nothing
  
          If ele Is Nothing Then Exit Sub
          ele.SendKeys "Username"
          .FindElementById("password").SendKeys "Password"
          .FindElementById("btn-login").Click
      End With
  
  
      With driver '&lt;==select todays date
          .get INURL  
          Dim drf As Object
          t = Timer
  
          Do
              Set drf = driver.FindElementsByCss(".col-sm-4 h2")
              If Timer - t &gt; MAX_WAIT_SEC Then Exit Do
          Loop While drf.Count = 0
  
          If drf.Count &gt; 0 Then
              .FindElementByClass("display-date").Click
  
              With .FindElementByXPath("//html/body/div/*/ul/li[1]")
                  .Click
              End With
  
              .FindElementByXPath("//div[contains(@button, 'applyBtn btn btn-small btn-success')]").Click
          End If
  
          i = 2
          Dim item As Object, nodeList As Object, r As Long
          t = Timer
  
          Do
              Set nodeList = driver.FindElementsByCss(".col-sm-4 h2")
              If Timer - t &gt; MAX_WAIT_SEC Then Exit Do
          Loop While nodeList.Count = 0
  
          If nodeList.Count &gt; 0 Then
              For Each item In nodeList
                  r = r + 1
                  ActiveSheet.Cells(2, r) = item.Text
              Next
          End If
      End With
  End Sub
  </code></pre>
  
  <p>I need it to click Apply causing the site to search Today's Date and then grab the data and display it on an excel sheet. Everything is working except being able to click the button. It is returning to me </p>
  
  <blockquote>
    <p>Run-time error '7': NoSuchElementError. </p>
  </blockquote>