1

Im trying to figure out how works the following-sibling navigation through elements, actually, Im practicing on try to get the name, product code, stock and the daily USD value and it works perfectly, it goes through the items and get differents info of each one, but I can't reach the price section, I think is inside another square on the div elements.

So the question is, how I can navigate to reach that field?, It needs to be following-sibling way because is the only method that worked to get the different information of each item.

Is there a way to say following-sibling::/div/div/span/h1 something like that, to navigate inside?

Here is the part of my newbie code and some images of examples:

Link: https://www.tecnoglobal.cl/tiendaonline/webapp/computadores/computador-desktop/239

        i = 2
            Set mysheet = Sheets("Hoja1")
                    Set products = driver.FindElementsByXPath(".//h1[@class='minificha__nombre-producto']")
            For Each product In products
        If product.FindElementByXPath("following-sibling::span").Text <> "" Then
    
            Workbooks.Open (Tecnogfile)
    
                mysheet.Cells(i, 1).Value = product.FindElementByXPath("following-sibling::span").Text
                    mysheet.Cells(i, 2).Value = product.FindElementByXPath("self::h1").Text
                        mysheet.Cells(i, 3).Value = product.FindElementByXPath("following-sibling::div").Text
                            mysheet.Cells(i, 5).Value = product.FindElementByXPath("//div//following-sibling::div").Text
                            
         e = 2
        Set precios = driver.FindElementsByXPath(".//div[@class='minificha__precio-preferencial minificha__precio-preferencial--solo ng-binding ng-scope']")
        
        For Each precio In precios
        
        mysheet.Cells(i, 4).Value = precio.FindElementByXPath("previous::span").Text
        
        Next
        
         e = e + 1

This is what works perfect

This is the price that im trying to reach

DebanjanB
  • 118,661
  • 30
  • 168
  • 217
Peter
  • 31
  • 5

2 Answers2

0

To identify the element with text as Cód TG you can use either of the following Locator Strategies:

  • Using FindElementByCss:

    bot.FindElementByCss("h1.minificha__nombre-producto +span")
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//h1[@class='minificha__nombre-producto']//following::span[1]")
    

To identify the element with text as sin stock disponible you can use either of the following Locator Strategies:

  • Using FindElementByCss:

    bot.FindElementByCss("h1.minificha__nombre-producto +span +span")
    
  • Using FindElementByXPath:

    bot.FindElementByXPath("//h1[@class='minificha__nombre-producto']//following-sibling::span[2]")
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
  • I just found a little software that can show live the xpath result, is called "Try Xpath" and I was testing all my Xpaths ideas and found the way finally, this is how I did it. Set products = driver.FindElementsByXPath(".//h1[@class='minificha__nombre-producto']") product.FindElementByXPath("following::div[3]").Text And now I got the price. Thanks you very much – Peter Feb 17 '21 at 14:30
0

I found a little software that show you the xpath live on the website, so you can test your ideas, I finally found my answer with this code.

driver.FindElementsByXPath(".//h1[@class='minificha__nombre-producto']")

product.FindElementByXPath("following::div[3]").text
Peter
  • 31
  • 5