Results 1 to 5 of 5

Thread: Insert value in web page and press button genera

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    You first need to ascertain the ID or unique about the HTML elements you want to interact with. You can do this by inspecting the webpage (or viewing the page source but that isn't as interactive as the inspect option)

    Once you have those, here we have the ID "combinations959" to enter the number into and then use the href property of the anchor HTML element to find it to click on.

    If it were me I'd install SeleniumBASIC 2.0.9, https://github.com/florentbr/seleniumbasic/releases, install it, then download the web driver that matches the browser in use. IE is a bit of a problem here as it involves more setup (I haven't tried it) here is what using chrome would look like.

    I'd go here Microsoft Edge WebDriver | Microsoft Edge Developer download the stable x64 file. Once downloaded, you take the msedgedriver.exe file from the zip and place it on the SeleniumBASIC folder at C:\Users\your user name\AppData\Local\SeleniumBASIC, rename it edgedriver.exe.

    In the VBA Editor, click tools references and select SeleniumBasic Type Library.
    The code would look something like

    Private Sub btnEdgeBrowser_Click()
        Dim eDriver As EdgeDriver
        Dim inputField As WebElement
        Dim paragraphElement As WebElement
        Dim codeRan As Boolean    
        codeRan = False
        Set eDriver = New EdgeDriver    
        eDriver.Get "https://risultatilotto.com/superenalotto/generatore-numeri/?fbclid=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek _
        5nY9F1AETH0c0GlwvbgmO7lBtLksJWj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw"
        eDriver.Wait 2000 ' wait 2 seconds for it respond    
        On Error GoTo exitTheCode    
        ' find the inputbox, they change the name of it
        ' get all the paragraphs and find the text Combinations:, take that paragraph and grab the inputbox in it
        For Each paragraphElement In eDriver.FindElementsByTag("p")
            If paragraphElement.Text = "Combinations: " Then
                Set inputField = paragraphElement.FindElementByTag("Input")
                Exit For
            End If
        Next    
        If Not inputField Is Nothing Then
            ' the correct inputbox was found, enter the required number
            inputField.Clear
            inputField.SendKeys "6"
            Set inputField = Nothing
        End If    
        ' to find the XPATH, right click the element in the inspect area and select Copy XPath
        ' click the anchor to proceed
        eDriver.FindElementByXPath("//*[@id='single-blocks']/div/div/div[1]/div/div/div/div[2]/div/a").Click
        eDriver.Wait 2000    
        codeRan = True
        exitTheCode:
        If Not codeRan Then
            MsgBox "There was an issue attempting to automate the page. " & vbCrLf & Error(Err), vbCritical, "Process Failed"
        End If    
        On Error Resume Next
        eDriver.Close
        Set eDriver = Nothing    
    End Sub
    Last edited by Aussiebear; 05-07-2025 at 12:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •