Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

457
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda