简体   繁体   English

我如何通过不包含 span puppeteer 来 select 一个元素

[英]How can i select an element by not containing span puppeteer

i am trying to select the first element which doesn't contain the span: Geef seintje from a dropdown menu.我正在尝试 select 第一个不包含跨度的元素:来自下拉菜单的Geef seintje I tried the code below, this piece of code selects the first element that contains Geef seintje but how can i make it that it selects the first element that doesn't contain this span?我尝试了下面的代码,这段代码选择了第一个包含Geef seintje的元素,但是我怎样才能让它选择不包含这个跨度的第一个元素?

const elements = await page.$x('//div[@role="presentation"][.//span[.="Geef seintje"]]');
console.log('found')
await elements[0].click();

The html can be find on https://www.zalando.nl/jordan-air-jordan-1-mid-sneakers-hoog-joc12n001-a18.html and then pressing the size dropdown menu, below is also a picture of the html. The html can be find on https://www.zalando.nl/jordan-air-jordan-1-mid-sneakers-hoog-joc12n001-a18.html and then pressing the size dropdown menu, below is also a picture of the html。 The only difference in the elements is that the one which are sold out contain an extra class which contains the span: Geef seintje .元素的唯一区别是售罄的元素包含一个额外的 class ,其中包含跨度: Geef seintje

picture of html html图片

You can use not in your xpath to say that it doesn't contain some text, and page.waitForXPath whic return a single element (the first) instead of page.$x which returns all matching elements:您可以在 xpath 中使用not来表示它不包含某些文本,并且page.waitForXPath返回单个元素(第一个)而不是返回所有匹配元素的page.$x

const firstElement = await page.waitForXPath("//span[not(contains(text(), 'Geef seintje'))]//ancestor::div[@role='presentation']");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM