I have a <section> tag in which there is <tfoot> tags and many <td> tags.

I want to store the 1st & 4th td elements of a in a Map, but i get index out of bounds exception.

Now, how can we use FindElement or FindElement method on a WebElement itself. Does this find all the child elements? Apologies as i have messed up all my code.

There are 14 tags on the page and i want to retrieve the text of td elements that are inside tfoot tag from each and every section, Product name and price, then store it in a String, String Map. Also, there is lot of whitespace in td element values.

                <table class="right">
                        <tr class="product">
                            <td>Product 1
                            <td class="rt">323.00</td>
                            <td class="rt">
                            <td class="rt">
                            <td class="rt">&nbsp;

enter image description here List sectionsList = driver.findElements(By.tagName("section"));

Iterator<WebElement> it = sectionsList.iterator();

Now, i want to store the td values in a Hashmap.

Map<String, String> map1 = new HashMap<String, String>();

for(int i=1; i<sections.size()+1; i++){ map1.put(sectionList.get(i).findElements(By.tagName("tfoot")).get(1).findElements(By.tagName("td")).get(0).getText() , sectionList.get(0).findElements(By.tagName("tfoot")).get(1).findElements(By.tagName("td")).get(3).getText()); }
for(int i=1; i<sections.size()+1; i++)

Why are you adding 1 to sections size, remove 1

for(int i=1; i<sections.size(); i++)

and also why starting from i=1 ? index starts from 0 to size-1 , so it should be i=0 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.