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: 440
See the picture
When we access the site we need to click on the element "1" (to select the option "Recent")
So, rightclick on the element, select Inspect
The page with the relevant html code will open (typically on a new frame on the right)
The clickable element is "2"; select, rightclick, select Copy, select Copy full XPath

Now you have the "address" to the item, to be used with the selenium method FindElementByXPath; once the element is selected you can "Click" it

Beware that XPath lasts until the next site revision, but it is the quickest method to point to an element (but it's not my favorite)
 

Attachments

  • CAROUSELL_Immagine 2023-02-17 110218.jpg
    CAROUSELL_Immagine 2023-02-17 110218.jpg
    196 KB · Views: 11
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
See the picture
When we access the site we need to click on the element "1" (to select the option "Recent")
So, rightclick on the element, select Inspect
The page with the relevant html code will open (typically on a new frame on the right)
The clickable element is "2"; select, rightclick, select Copy, select Copy full XPath

Now you have the "address" to the item, to be used with the selenium method FindElementByXPath; once the element is selected you can "Click" it

Beware that XPath lasts until the next site revision, but it is the quickest method to point to an element (but it's not my favorite)
Great advice and information you have provided me, now I can understand and enable me to explore more and better position to figure it out when the next issue occurs. Thanks alot.
 
Upvote 0
XPath is a quick shortcut to the element, but in my opinion it's quite unstable, ie changes easily.
A more reliable way is looking at the tags and attributes, that is using FindElementsByCss, or FindElementsByClass or FindElementsByTag.
FindElementsByCss combines tag & attributes; for example
VBA Code:
Set tObj = WPage.FindElementsByCss("div[class='D_Ss M_VL']")
will return a collection with 8 DIVs that in the page have that Class
The one to click is the second, thus
VBA Code:
tObj(2).Click

Selenium offers both FindElementByXYZ (return the first element, if exists; or rise an error at run-time) and FindElementsByXYZ (note "Elements", not Element; it returns the collection of elements, or a collection whose ".Count=0" in case no any element is grabbed)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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