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

453
Vistas
Xpath: How to combine these two child node to get parent node?

I am new to XPath and confused. Anyone can have a quick glance and see what is wrong in my syntax?

I'm trying to select all direct child div's of id="list-overview" which has two child nodes somewhere down their tree containing data-price<=20 and a div containing "Orange" text

let xy = $x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20]][./div/a/div/div[@class='fruit'][contains(.,'Orange')]])`)

to break it up. I have tested these two separately and they worked.

`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20]]`
`//*[@id="list-overview"]/div[./div/a/div/div[@class='fruit'][contains(.,'Orange')])]`

I just can't seem to combine them somehow and not sure what I'm doing wrong?

EDIT:

Tried the suggestions and the following xpath doesn't throw an exception anymore. But it returns empty Array while there are elements matching price < 20 and fruit="Orange"

$x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20] and ./div/div/a/div/div[@class='fruit'][contains(.,'Orange')]]`)
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If I understand your idea, you are missing the logical and between these 2 conditions. I corrected the XPath expression accordingly. Please try this:

let xy = $x(`//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20] and ./div/a/div/div[@class='fruit'][contains(.,'Orange')]])`)

UPD
Please try this:

let xy = $x(`//*[@id="list-overview"]/div[.//div[@data-price<=20] and .//div[@class='fruit'][contains(.,'Orange')]])`)
about 4 years ago · Juan Pablo Isaza Denunciar

0

Instead of this

$x(//*[@id="list-overview"]/div[./div/a/div/div/div[@data-price<=20]][./div/a/div/div[@class='fruit'][contains(.,'Orange')]]))

You could do this to combine both of them,

to tightly couple both the child

$x(//*[@id="list-overview"]/div[./descendant::div[@data-price<=20]] and [./div/a/div/div[@class='fruit'][contains(.,'Orange')]])

or to either have one of them and still you would want to proceed further.

$x(//*[@id="list-overview"]/div[./descendant::div[@data-price<=20]] or [./div/a/div/div[@class='fruit'][contains(.,'Orange')]])

Also, I have included descendant to make it more readable.

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