Home > OS >  Extracting the child of a parent element Python Selenium
Extracting the child of a parent element Python Selenium

Time:07-12

    <a  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-Κάρτα-Γραφικών-PCI-E-x16-4-0-με-HDMI-και-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

CodePudding user response:

You can try below xpath

//a[contains(text(), '871')]

CodePudding user response:

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

  • Related