Consulting

Results 1 to 5 of 5

Thread: Insert value in web page and press button genera

  1. #1

    Insert value in web page and press button genera

    Enter value in input box on web page and press generate button


    https://risultatilotto.com/superenal...miRJiprneGOzvw

    Enter the value 6 in the combinations box and press the generate button.
    I am using IE object in my project.
    Thank you
    Sal
    1 help 1 pizza
    2 help 1 pizza 1 caff?
    3 help 1 pizza 1 caff? 1 mozzarella
    ...
    Spaghetti, Lasagne and Tortellini for the "Lady" ;-)

  2. #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.

  3. #3
    Quote Originally Posted by jdelano View Post
    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
    hi .... error in
    eDriver.Get "https://risultatilotto.com/superenalotto/generatore-numeri/?fbclid=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek _
    5nY9F1AETH0c0GlwvbgmO7lBtLksJWj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw"
    Attached Images Attached Images
    Last edited by Aussiebear; 05-07-2025 at 12:34 PM.
    Sal
    1 help 1 pizza
    2 help 1 pizza 1 caff?
    3 help 1 pizza 1 caff? 1 mozzarella
    ...
    Spaghetti, Lasagne and Tortellini for the "Lady" ;-)

  4. #4
    Quote Originally Posted by sal21 View Post
    hi .... error in
    eDriver.Get "https://risultatilotto.com/superenalotto/generatore-numeri/?fbclid=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw"
    Attached Images Attached Images
    Sal
    1 help 1 pizza
    2 help 1 pizza 1 caff?
    3 help 1 pizza 1 caff? 1 mozzarella
    ...
    Spaghetti, Lasagne and Tortellini for the "Lady" ;-)

  5. #5
    It looks like the website URL has been rerouted to the local 127.0.0.1 web server. Do you have it setup in your hosts file in the folder C:\Windows\System32\drivers\etc\?

Posting Permissions

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