Access element with same name within a class

shirazx3

New Member
Joined
Jul 7, 2022
Messages
23
Office Version
  1. 2021
Platform
  1. Web
As depicted in the picture below, I want to access the data within the red box. The main class has 5 "row" elements enclosed within it. How can I display those values on in an excel cell using Selenium Chromedriver.
1657533619307.png
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Whithout access the web page and the possibility of inspecting its html code these exercizes are like driving wearing a blindfold...
Supposing you wish to list in columns A:E the content of the five element with Class="row"
The first question is: how to I catch the collection of the five "row" elements.
If they are the only "row" elements of the webpage document then you will get the job done quite easily:
Code:
Set myColl = WPage.FindElementsByClass("row")

If that is not the case then let's assume that there is only one element having Class="input-form-column"; then we might use
Code:
Set myColl = WPage.FINFelementsbyclass("input-form-column")(1).FindElementsByClass("row")
(in my code, WPage is the Selenium Chrome driver)

If that is still not the case then you have to find your way to addressing the proper elements

Now, if with one of the two options you addressed the right elements, we can try to access the "<h6>" and its content:
Code:
Sheets("Sheet1").Select
For I = 1 To myColl.Count
    RawTxt = myColl(I).FindElementsByTag("h6")(1).Text
    mySplit = Split(Replace(RawTxt, Chr(34), "", , , vbTextCompare) & " " & Chr(10), Chr(10), , vbTextCompare)
    Cells(2, I).Resize(UBound(mySplit) + 1, 1).Value = Application.WorksheetFunction.Transpose(mySplit)
Next I
This will put in N columns of the selected sheet the several lines that are texted within the <h6> elements.
Result is guaranteed, like driving a car wearing a blindfold
 
Upvote 0
Hello once again, hope you are doing well.
Sorry for the inconvenience but to access that data, one requires username and password that is why I was unable to post much about it. I will put some screengrabs to make it more clear.

The data I'm looking for is in this table. I just want to display the underlined data in a cell(1,1)
1657617895486.png
1657617935966.png


The source code behind the table is within the red box here and there is no other class with name "input-form-column.username-col" but there are other "row" elements within other classes.
1657618183381.png


I'm trying this code but it gives me "index was outside the bounds of the array" error.
1657618592993.png

VBA Code:
Private ch As Selenium.ChromeDriver

Sub Test()

Set ch = New Selenium.ChromeDriver

ch.Get "https://www.uplandoptimizer.com/"
ch.FindElementsByClass("btn")(1).Click
ch.FindElementsByClass("form-control")(1).SendKeys ("username")
ch.FindElementsByClass("form-control")(2).SendKeys ("password")
ch.FindElementsByClass("btn")(1).Click
Set a = ch.FindElementsByClass("input-form-column.username-col")(4).FindElementsByClass("row")
    Cells(1, 1).Value = a.FindElementsByTag("h6")(1).Text

End Sub
 
Upvote 0
After submitting username and password you should wait a few seconds to make sure that the login process is completed. Thus try:
Code:
ch.FindElementsByClass("btn")(1).Click
ch.Wait 2000                      ‘Wait 2 secs         ***
From that on you should clarify what you wish to catch: all the <h6> that (I guess) are within the 5 elements having class="row" or only the <h6> of the fourth "row" element?
In this second hypotesis you should use, to stay with your approach:
Code:
Set a = ch.FindElementsByClass("input-form-column.username-col")(1).FindElementsByClass("row")    'collection of the "row"
Cells(1, 1).Value = a(4).FindElementsByTag("h6")(1).Text
 
Upvote 0
I am trying to catch the <h6> of fourth row only. (Other "row" above also have <h6> element but I am only interested in the <h6> of fourth row).
1657630050664.png



After using the approach, I am given this error.
1657629757698.png
 
Upvote 0
And which is the line in error? If you "continue" the macro (using F5 while in debug mode), the same line stays in error or the macro continue?
 
Upvote 0
1657636939265.png

Yes the same line stays in error when I press F5 while in debug mode.
 
Upvote 0
Use
VBA Code:
Set a = ch.FindElementsByClass("input-form-column")(1).FindElementsByClass("row")
 
Upvote 0
It gives the same error at the same line. Pressing F5 while in debug mode keeps the same line in error.
 
Upvote 0
First try setting a wait of 5 seconds:
VBA Code:
ch.Wait 5000

It it still fails then:
-replace the current Set a = etc etc and the next Sheet2.Cells(etc etc with
VBA Code:
Debug.Print ">>>>"
Set A = ch.FindElementsByClass("input-form-column")
Debug.Print A.Count
If A.Count > 0 Then
    Debug.Print ch.FindElementsByClass("input-form-column").Attribute("innerHTML")
End If
Debug.Print "<<<<"
-run the macro
-at the completion of the macro open the vba editor and open its "Immediate Window" (typing Contr-g should do the job; or menu /View /Immediate window)
-copy what is printed there, from >>>> to <<<< and insert that text in your next message
 
Upvote 0
Solution

Forum statistics

Threads
1,214,833
Messages
6,121,857
Members
449,051
Latest member
excelquestion515

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