Click here to Skip to main content
15,610,556 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
When I do a "for" on all the search results in order to enter the first output page and extract data and exit it to enter the next output, it repeats the entry of the first product, so I tried to create a "for" to enter the next output, not the same output.

This is my attempt:

What I have tried:

            For Each webElement2 As IWebElement In Me.driv.FindElements(By.XPath("//*[@class='MVVflb-haAclf V0h1Ob-haAclf-d6wfac MVVflb-haAclf-uxVfW-hSRGPd']"))
                Dim flag2 As Boolean = Operators.CompareString(Me.ttt.Text, "", False) = 0
                If flag2 Then
                    Me.ttt.Text = webElement2.ToString
                    Me.ttt.AppendText(Environment.NewLine + webElement2.ToString())
                End If
        Catch ex As Exception
        End Try

        Dim flag3 As Boolean = Me.nnm <= Me.ttt.Lines.GetUpperBound(0)
        If flag3 Then
                For Each webElement3 As IWebElement In Me.driv.FindElements(By.Id(ttt.Lines(nnm)))
                    Dim flag4 As Boolean = Operators.CompareString(webElement3.ToString(), Me.ttt.Lines(Me.nnm).ToString(), False) = 0
                    If flag4 Then
                            Exit Try
                        Catch ex3 As Exception
                        End Try
                    End If
            Catch ex As Exception
            End Try
Updated 4-Mar-22 14:18pm
Richard MacCutchan 4-Mar-22 6:47am    
So which code has the problem, and what is it exactly?
MR. S3eeD_# 4-Mar-22 8:20am    
I am extracting data from Google Map, but after entering the first output to extract the data from it and then returning again to the outputs, I want it to enter the next output, not the first output
Richard MacCutchan 4-Mar-22 8:26am    
You already stated that, and you still have not explained where the error occurs in the code above.
MR. S3eeD_# 4-Mar-22 8:35am    
After extracting all ids of the results using the first for event
The error exists when extracting all the "ids" of the results and this is the error message:
'no such element: Unable to locate element: {"method":"css selector","selector":"#c204bb7f\-98d8\-45af\-9d71\-1f009fe0d4d5"}

code: wwww.FindElement(By.Id("c204bb7f-98d8-45af-9d71-1f009fe0d4d5")).Click()
Richard MacCutchan 4-Mar-22 8:42am    
On reflection I suspect the criteria used by the FindElements function are not based solely on the id value, as used in the above code. I would suggest checking the documentation to see if there are any options that may help.

1 solution

I solved the problem by replacing "ttt.Text = webElement2.ToString" with "ttt.Text = webElement2.GetAttribute("aria-label").ToString()"
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900