Vba Selenium problems "no such element error"

JasonLim

New Member
Joined
Dec 23, 2021
Messages
31
Office Version
  1. 365
Platform
  1. Windows
I had this pop out box stated with "no such element error". I really don't know what's wrong with the code. This basic code is actually looking up for the search box and input text which is ABC. I hope I can find someone who can kindly guide me. Your help will be very much appreciated. TQ

Set mybrowser = New Selenium.ChromeDriver

sel.Start "chrome", "Carousell Singapore | Buy & Sell Goods, Cars, Services and Property"
sel.Get "/"
'Stop

sel.FindElementByCss("a.D_pG.D_pH.D_pT.D_mz").SendKeys "ABC"
 

Attachments

  • Screenshot 2022-06-27 220141.jpg
    Screenshot 2022-06-27 220141.jpg
    221.7 KB · Views: 366

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thank you for the feedback
(There are so many geniuses on this forum, but you are speaking to an amateur)
 
Upvote 0
Hi, Mr Anthony47, how can I select the option from a pull down list for example recent. I had no idea how to do it, Can you kindly help me with that? : ) Your help will be very much appreciated.

Sub AlwayUseTheToTest()

Dim cd As New ChromeDriver

cd.Start "chrome", "Carousell Singapore | Buy & Sell Goods, Cars, Services and Property"
cd.Get "/"
'Stop

cd.FindElementByCss(".D_rv.D_rw.D_rI.D_qZ").SendKeys "samsung note 22 ultra"
cd.FindElementByCss(".D_nT.D_nH.D_oh.D_nV.D_nI.D_rb").Click
cd.FindElementByCss(".D_uf.D_vZ.D_wg").Click


cd.FindElementByCss(".D_la.D_kS.D_lb.D_lf.D_li.D_ll.D_ln.D_kW").Click




End Sub
 
Upvote 0
I shall not be able to look at the site for the next 36 hours, hope that someone else responds in the meantime
 
Upvote 0
Given that there is not a receipe that fits all the needs, I was able to select “Recent” in the second selection group using the following snippet:
Code:
Dim WPage As Selenium.WebDriver, myUrl As String
Dim tObj As Object, myTim As Single, AColl As Object
Dim noBB As Boolean
'
myTim = Timer
'Crea Driver:
'    Set WPage = CreateObject("Selenium.EdgeDriver")
    Set WPage = CreateObject("Selenium.CHRomedriver")
'
myUrl = "https://www.carousell.sg/search/toys?SearchId=GL7fvY&addrecent=true&canChangeKeyword=true&includeSuggestions=true&searchId=3XYjuS"    '<<< YOUR Url
'
WPage.Get myUrl
WPage.Wait 500
Debug.Print "Page loaded", Format(Timer - myTim, "0.0")
'
'Search the menu
Set AColl = WPage.FindElementsByClass("D_ut")
Debug.Print "AColl.Count="; AColl.Count
'Click the second one:
AColl(2).Click
WPage.Wait 500
'Catch the Radiobuttons:
Set tObj = WPage.FindElementsByClass("D_yS")
Debug.Print "tObj.Count=" & tObj.Count
'... and click the second one:
tObj(2).Click
WPage.Wait 500
Set AColl = WPage.FindElementsByClass("D_xY")
If AColl.Count > 2 Then
    If InStr(1, AColl(2).Text, "Recent", vbTextCompare) > 0 Then
        Debug.Print "Recent has been selected"
        noBB = False
    Else
        noBB = True
    End If
Else
    noBB = True
End If
Debug.Print "noBB=" & noBB
If noBB Then
    AppActivate (Application.Caption)
    MsgBox ("Selecting Recent failed; select it manually before closing the msgbox")
    ''Stop            '<<< This is only for test
End If
The trick is inspecting the relevant webelements involved in the automation, finding a method for addressing the right one, then execute the right command with the element; this latter operation is mainly a try-and-error process, and thus requires time and patience, nowadays both rare elements for everybody…
 
Upvote 0
Bro, you are amazing, it works perfectly. Thank you alot. But when I ask, I notice this website keeps changing key code names everyday, Below, are an example, do you have any idea how to solve such an issue?

'Search the menu
Set AColl = WPage.FindElementsByClass("D_ut")

Set AColl = WPage.FindElementsByClass("D_xV")

Another example

'Catch the Radiobuttons:
Set tObj = WPage.FindElementsByClass("D_yS")

Set tObj = WPage.FindElementsByClass("D_yF")
 
Upvote 0
Indeed the Classes that I selected are useless today...

Let's try catching the containers (<div>) using their "style" attribute...
VBA Code:
Dim WPage As Selenium.WebDriver, myUrl As String
Dim tObj As Object, myTim As Single, AColl As Object, BColl As Object
Dim noBB As Boolean, MI As Long
'
myTim = Timer
'Crea Driver:
'    Set WPage = CreateObject("Selenium.EdgeDriver")
    Set WPage = CreateObject("Selenium.CHRomedriver")
'
myUrl = "https://www.carousell.sg/search/toys?SearchId=GL7fvY&addrecent=true&canChangeKeyword=true&includeSuggestions=true&searchId=3XYjuS"    '<<< YOUR Url
'
WPage.Get myUrl
WPage.Wait 500
Debug.Print "Page loaded", Format(Timer - myTim, "0.0")
'
'Search the menu container:
Set AColl = WPage.FindElementsByTag("div")
For I = 1 To AColl.Count
    If InStr(1, AColl(I).attribute("style"), "top:", vbTextCompare) = 1 Then
        Debug.Print "Found menus DIV, # " & I
        Exit For
    End If
Next I
MI = I
'...and click the second one:
Set tObj = AColl(MI).FindElementsByTag("svg")
tObj(2).FindElementByXPath("./..").Click
WPage.Wait 500
'Search the RadioButtons Container:
Set BColl = WPage.FindElementsByTag("div")
For I = 1 To BColl.Count
    If InStr(1, BColl(I).attribute("style"), "left:", vbTextCompare) = 1 Then
        Debug.Print "Found RadioButtons DIV, # " & I
        Exit For
    End If
Next I
'...and click the second one:
Set tObj = BColl(I).FindElementsByTag("input")
tObj(2).Click
WPage.Wait 500
Debug.Print "ZxZx", AColl(MI).Text
If InStr(1, AColl(MI).Text, "Recent", vbTextCompare) > 0 Then
    Debug.Print "Recent has been selected"
    noBB = False
Else
    noBB = True
End If
Debug.Print "noBB=" & noBB
If noBB Then
    AppActivate (Application.Caption)
    MsgBox ("Selecting Recent failed; select it manually before closing the msgbox")
    ''Stop            '<<< This is only for test
End If
It works ...as of now; i'll check it works even tomorrow...
 
Upvote 0
Solution

Forum statistics

Threads
1,216,741
Messages
6,132,448
Members
449,728
Latest member
teodora bocarski

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