0
    <a class="js-sku-link sku-link" title="Inno 3D GeForce RTX 3080 10GB GDDR6X X3 LHR Κάρτα Γραφικών PCI-E x16 4.0 με HDMI και 3 DisplayPort" data-e2e-testid="sku-price-link" href="/s/35993359/Inno-3D-GeForce-RTX-3080-10GB-GDDR6X-X3-LHR-%CE%9A%CE%AC%CF%81%CF%84%CE%B1-%CE%93%CF%81%CE%B1%CF%86%CE%B9%CE%BA%CF%8E%CE%BD-PCI-E-x16-4-0-%CE%BC%CE%B5-HDMI-%CE%BA%CE%B1%CE%B9-3-DisplayPort-N30803-106X-1810VA44H.html">
        <span>από</span>
        871,28 €
    </a>

Hello. I have the above HTML and i want to select the element that has the price (871,28 that is). I am using python and selenium. I have tried

driver.find_elements_by_class_name("js-sku-link sku-link")

but this gives me the parent element and i dont know how to choose the second child of it. Thank you very much for your help

2 Answers2

0

You can try below xpath

//a[@class='js-sku-link sku-link']
Ketan Pardeshi
  • 516
  • 1
  • 5
  • 8
0

Do not use the findElements method and add /a[INDEX]

Additionally you can trim the string while fetching the xpath if the price will be constant. Read the details here

indayush
  • 55
  • 2
  • 9
  • Thank you for your answer. The price is not constant. Can you be more specific about the findelements example? –  Jul 12 '22 at 11:02
  • Can you share the element along with it's parent. That way i will be able to give you a better xpath. The code is like following in java. You can change it to suit it as per python. ```WebElement e = driver.findElement(By.xpath("//a[contains(@title,'title="Inno 3D GeForce RTX 3080 10GB GDDR6X X3')]"));``` It might look something like - ```driver.find_element_by_xpath("//a[contains(@title,'title="Inno 3D GeForce RTX 3080 10GB GDDR6X X3')]")``` – indayush Jul 12 '22 at 11:12
  • i am not exactly sure of what you aske me to share with you. The element that i want is the one that has as text 871.28 but this is not a constant, it might change. The same stands for the text "Inno 3D GeForce RTX 3080 10GB GDDR6X X3". It can also change name –  Jul 12 '22 at 11:13
  • Can you share the link of the webpage where this element is ? – indayush Jul 12 '22 at 11:15
  • https://www.skroutz.gr/c/55/kartes-grafikwn-vga/f/1180098/GeForce-RTX-3080.html?o=rtx+3080&order_by=pricevat&order_dir=asc –  Jul 12 '22 at 11:16
  • I have updated my answer. It will give you first price of item. you can use FindElements if you want to check for others. – Ketan Pardeshi Jul 12 '22 at 12:01
  • Use the following code to store a list of xpaths. This will give you price of all the cards. ```driver.find_elements(By.XPATH, "//div[contains(@class,'price react-component')]//a")``` If you want the names of the cards, the get text of the elements from this xpath - ```//div[@class='card-content']//h2/a``` . If the currency symbol is a bother, then you can replace the text with empty string. – indayush Jul 12 '22 at 15:42