0

I have the following code:

<div class="ProductSize-group"> <div class="c-form-field c-form-field--radio c-form-field--disabled c-form-field--unavailable ProductSize"><label for="input_radio_size_060" aria-hidden="true" class=""><span class="c-form-label-content">06.0</span></label><input name="size" aria-label="Size 06.0, out of stock" id="input_radio_size_060" type="radio" disabled="" required="" value="06.0"></div> <div class="c-form-field c-form-field--radio c-form-field--disabled c-form-field--unavailable ProductSize"><label for="input_radio_size_065" aria-hidden="true" class=""><span class="c-form-label-content">06.5</span></label><input name="size" aria-label="Size 06.5, out of stock" id="input_radio_size_065" type="radio" disabled="" required="" value="06.5"></div> </div> 

This is just part of it. I need to check if this div contains class

<div class="c-form-field c-form-field--radio c-form-field--disabled c-form-field--unavailable ProductSize"> 

Specifically check if this div contains class c-form-field--unavailable

This is what I have:

 const productSizeOptions = await page.$(".ProductSize-group"); productSizeOptions.map(productSizeOption => { }) 

But I can't figure out how to loop through each class to see if it exists in the element or not. Any ideas?

2 Answers 2

2

Just use :not

await page.$(".ProductSize-group:not(.c-form-field--unavailable)"); 
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Element.classList:

const foo = await page.$('.foo'); const hasBarClass = await page.evaluate( element => element.classList.contains('bar'), foo ); if (!hasBarClass) console.log('Element.foo has no .bar class.'); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.