vba to click button in IE inside form on a website

RodrigoFinguer

Board Regular
Joined
Jun 13, 2017
Messages
75
Hello guys, i really need your help!!

I want to get a value from excel and paste inside a website and click a button to get information about this value from excel.

I managed to copy value from excel and paste on the website, but i can't click on "Find" button, there is inside a form on this website.

This is the wesite code and the highlighted button code:


<form>



For which product are you searching Product data?



<input name="search-input-productdata" id="search-input-productdata" type="text" value="" data-bind="value:SearchTerm.SearchText,valueUpdate:'afterkeydown'">

<button class="button" id="search-button-productdata" aria-disabled="false" *******="return tracker.track4App('DuD_Productdata', 'Product data', 'BTN_FIND','Clicked: [Find]')" type="submit" aria-role="button">
Find
</button>






Here is the code i am using:

Sub Automate_IE_Load_Page()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As InternetExplorer
Dim ieApp As Object
Dim objElement As Object
Dim objCollection As Object
Dim allHREFs As New Collection
Dim btn As HTMLButtonElement

'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")

'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True


'Define URL
URL = "https://www.sew-eurodrive.de/os/dud/?tab=productdata&country=DE&language=en_US"

'Navigate to URL
IE.navigate URL

' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."

' Wait while IE loading...
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop


'Webpage Loaded
Application.StatusBar = URL & " Loaded"

'Coloca a data de um ano atrás no campo "Data De" e hoje no "Data Até"
IE.document.getElementById("search-input-productdata").Value = Sheets("Planilha2").Range("B2").Text
'IE.document.getElementById("search-button-productdata").Click

'1ST attempt to click
Set btn = IE.document.querySelector("button[class=button]")
btn.Click

'2nd attempt to click
Set tags = IE.document.getElementsByTagName("button")
For Each tagx In tags
If tagx.innerText = " Find " Then
tagx.Click
Exit For
End If
Next


<style>
.hist-table tbody tr td {
padding:0;
vertical-align:top;
}
</style>


</form>
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this.
Code:
IE.document.forms(0).submit
 
Upvote 0
Now, i need to get some information from the result.
I need the value from class="dud-tablecol-stretch"

HTML:
<div data-bind="css: IsFromSerialNumberUsa() ? 'unit size1of1' : 'unit size1of2'" class="unit size1of2">            <p class="hd h3">Technical data</p>
<div data-bind="with: SearchResult, visible: SearchResultNotEmpty" class="mod mod-table" data-composer-template="light-tech" data-connectors="driveguide" style="">        <table class="table light" id="productdata-technicaldata-table">        <tbody data-bind="foreach: Details">            <tr>    <td class="dud-tablecol-minwidth-30pct">        <span data-bind="text: Key">Serial number</span>     </td>    <td class="dud-tablecol-stretch">        <span data-bind="text: Value">70.0222611602.0001.13</span>     </td></tr>
                    <tr>    <td class="dud-tablecol-minwidth-30pct">        <span data-bind="text: Key">Speed [r/min]</span>     </td>    <td class="dud-tablecol-stretch">        <span data-bind="text: Value">1690 / 36</span>     </td></tr>
</div>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top