Search for an item in a search box in a website.

API_newnoob

New Member
Joined
Jun 6, 2020
Messages
21
Office Version
  1. 2016
Platform
  1. Windows
Hi I am new to this, i watched a few tutorials and tried out on my own and realize that i can't even do a search in the search box of the webpage.

Below is my code that i tried.

VBA Code:
Sub Automate_IE_Load_Page()
'This will load a webpage in IE
    Dim i As Long
    Dim URL As String
    Dim IE As Object
    Dim objElement As Object
    Dim objCollection As Object
 
    '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://shopee.sg/"
 
    '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...
    'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertently skipping over the second loop)
    Do While IE.readyState = 4: DoEvents: Loop   'Do While
    Do Until IE.readyState = 4: DoEvents: Loop   'Do Until
 
    'Webpage Loaded
    Application.StatusBar = URL & " Loaded"

    'what i tried.
    'IE.document.getElementById("shopee-searchbar-input").Value = "value"       'Find by ID
    'IE.document.getElementById("shopee-searchbar-input__input").Value = "value"       'Find by ID
    'IE.document.getElementsByTagName("shopee-searchbar-input").Value = "value"        'Find by tag
    'IE.document.getElementsByTagName("shopee-searchbar-input__input").Value = "value"        'Find by tag
    'IE.document.getElementsByClassName("shopee-searchbar-input").Value = "value"      'Find by class
    'IE.document.getElementsByClassName("shopee-searchbar-input__input").Value = "value"      'Find by class
    'IE.document.getElementsByName("shopee-searchbar-input").Value = "value"           'Find by name
    'IE.document.getElementsByName("shopee-searchbar-input__input").Value = "value"           'Find by name
    
    'Unload IE
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
    
End Sub

I have also upload an image of the webpage and highlight the search box that i want to input a text.

Can someone tell me what i did wrong?
 

Attachments

  • Untitled.gif
    Untitled.gif
    98.4 KB · Views: 47

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
The Search TextBox might be in a different frame. I use SideeX in Google Chrome and Record my clicks to find out what Frame I am in.

SideeX Website
 
Upvote 0
What about my feedback? You need to find out which frame you are in.
 
Upvote 0
I used Selenium Chrome for my Internet Automation... Try this code. I was successful with my
Selenium code below your code.

VBA Code:
Sub Automate_IE_Load_Page()
Dim i As Long, URL As String, IE As Object, objElement As Object, objCollection As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    URL = "https://shopee.sg/"
    IE.navigate URL
    Application.StatusBar = URL & " is loading. Please wait..."
    Do While IE.readyState = 4: DoEvents: Loop
    Do Until IE.readyState = 4: DoEvents: Loop
    Application.StatusBar = URL & " Loaded"
    IE.document.getElementByClass("shopee-popup__close-btn").Click
    IE.document.getElementbyCss("input.shopee-searchbar-input__input").SendKeys "test"
    IE.document.getElementByXPath("//button[@type='button']").Click
    Stop
    Set IE = Nothing
    Set objElement = Nothing
    Set objCollection = Nothing
End Sub


this is what worked for me when using Selenium and Google Chrome. IE is too slow and boring.

VBA Code:
Sub MrExcel()
Dim activeELE As String
Dim bot As New Selenium.WebDriver, ele As WebElement, Xpath As String
bot.Start "chrome", "https://shopee.sg"
bot.Get "/"
bot.FindElementByClass("shopee-popup__close-btn").Click
bot.FindElementByCss("input.shopee-searchbar-input__input").SendKeys "test"
bot.FindElementByXPath("//button[@type='button']").Click
Stop
End Sub
 
Upvote 0
Dear @VBE313,

Thank you very much for your efforts and input, i tried it out but unfortunately, there is a run time error 438 on the line "IE.document.getElementByClass("shopee-popup__close-btn").Click" .

Is there something i am missing out?

I tried googling and altering but it just does not work, i get a different run time error 424 or some other errors.

I initially wanted to use selenium to automate google chrome as I too, think that IE is slower.

However, i am unable to download anything from the web and therefore i am constrained to use whatever is provided.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
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