Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
How to access parent text which has no tag through xPath

Please find the code below

<div class="xsmall-12 medium-6 columns">
                        <label class="device-attribute-label" rel="tooltip" title="Proprietary/trade name of the medical device as used in the labeling or catalog.">Brand Name:</label>
                        Snowden-Pencer
                        <br>
                        <label class="device-attribute-label" rel="tooltip" title="Identifies a category or design of devices that have specifications, performance, size, and composition within limits set by the company.">Version or Model:</label>
                        32-0044
                        <br>
                        <label class="device-attribute-label" href="#" rel="tooltip" title="Whether the device is currently offered for sale by the device company. A device no longer in commercial distribution may or may not still be available for purchase in the marketplace.">Commercial Distribution Status:</label>
                        In Commercial Distribution
                        <br>
                        <label class="device-attribute">Catalog Number:</label>
                        32-0044
                        <br>
                        <label class="device-attribute">Company Name:</label>
                        CAREFUSION 2200, INC
                    </div>

I have to retrieve parent text like "Snowden-Pencer", "32-0044","CAREFUSION 2200, INC" individually

This is what I have tried

element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/div[1]/div[2]/div[1]/div[2]/section[1]/div[1]/div[1]//div[1]/*"))
    )

Output is:

output = Brand Name:

I need to find the correct XPath. Please help me out, thanks in advance

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

If you're using selenium you can use the getText() method so it will perhaps look like driver.findElement(webdriver.By.xpath("XPath")).getText() Altought that's for Java.

For python I believe it looks something like this

value_text = driver.find_element_by_xpath("XPath").text

about 4 years ago · Juan Pablo Isaza Denunciar

0

Can you try below two xpaths

//label[@rel='toltip']/*
about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use regex

import re
a = """<div class="xsmall-12 medium-6 columns">
                        <label class="device-attribute-label" rel="tooltip" title="Proprietary/trade name of the medical device as used in the labeling or catalog.">Brand Name:</label>
                        Snowden-Pencer
                        <br>
                        <label class="device-attribute-label" rel="tooltip" title="Identifies a category or design of devices that have specifications, performance, size, and composition within limits set by the company.">Version or Model:</label>
                        32-0044
                        <br>
                        <label class="device-attribute-label" href="#" rel="tooltip" title="Whether the device is currently offered for sale by the device company. A device no longer in commercial distribution may or may not still be available for purchase in the marketplace.">Commercial Distribution Status:</label>
                        In Commercial Distribution
                        <br>
                        <label class="device-attribute">Catalog Number:</label>
                        32-0044
                        <br>
                        <label class="device-attribute">Company Name:</label>
                        CAREFUSION 2200, INC
                    </div>"""
b = re.findall(r' (.*?)\n', a)
c = [x.lstrip().rstrip() for x in b if '<' not in x and '>' not in x]
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda