0

Hello I want the get the data printed from my size webelement

This is the site HTML

<div class="size-option"><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="163" data-quantity="4">
                            <span class="checker-box">8</span>
                        </label><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="164" data-quantity="5">
                            <span class="checker-box">8.5</span>
                        </label><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="165" data-quantity="3">
                            <span class="checker-box">9</span>
                        </label><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="167" data-quantity="8">
                            <span class="checker-box">10</span>
                        </label><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="168" data-quantity="5">
                            <span class="checker-box">10.5</span>
                        </label><label class="custom-input type-box size-box">
                            <input class="form-control" type="radio" name="sizeChartId" value="169" data-quantity="3">
                            <span class="checker-box">11</span>
                        </label></div>

print(size.text) gives me

AttributeError: 'list' object has no attribute 'text'

Here is my element size=driver.find_elements_by_xpath("//*[@id='product']/div[1]/div/div[1]/div[2]/div/div[3]/div") and

for value in size:
    print(value.text)

Doesn't work

print(size[0].text)

Just give me empty, but I want the span Numbers in a list printed.

1 Answer 1

1

Since "size" is a list of web elements if you wish to print text values of all it's elements, you have to iterate through the list and print each element text, like this:

size=driver.find_elements_by_xpath("//*[@id='product']/div[1]/div/div[1]/div[2]/div/div[3]/div")
for el in size:
    print(el.text)

Otherwise, if size intended to be a single element, I have no idea what is the "//*[@id='product']/div[1]/div/div[1]/div[2]/div/div[3]/div" XPath locating - if so you should use

size=driver.find_element_by_xpath("//*[@id='product']/div[1]/div/div[1]/div[2]/div/div[3]/div")

instead of

size=driver.find_elements_by_xpath("//*[@id='product']/div[1]/div/div[1]/div[2]/div/div[3]/div")
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, you appreciate you taking the time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.