PDA

View Full Version : Insert value in web page and press button genera



sal21
04-26-2025, 12:16 AM
Enter value in input box on web page and press generate button


https://risultatilotto.com/superenalotto/generatore-numeri/?fbclid=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw

Enter the value 6 in the combinations box and press the generate button.
I am using IE object in my project.
Thank you

jdelano
04-26-2025, 06:10 AM
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 (https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH#downloads) 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=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_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

sal21
04-27-2025, 12:13 AM
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 (https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/?form=MA13LH#downloads) 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=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_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=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw"

sal21
04-27-2025, 12:17 AM
hi .... error in
eDriver.Get "https://risultatilotto.com/superenalotto/generatore-numeri/?fbclid=IwY2xjawJ5Z2hleHRuA2FlbQIxMQABHs11Hnek5nY9F1AETH0c0GlwvbgmO7lBtLksJ Wj6jWLeIi2JEs9r4P6XTgWA_aem_-GZ_Jp-KmiRJiprneGOzvw"

jdelano
04-27-2025, 04:18 AM
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\?