0

I have some problems locating elements into a web page like this:

<tr id="filter100" style="...." idx=0
    <td>
       <div onclick=... style=...
         <table dir = "fil">
           <tbody>
             <tr>
              <td>
               <img id="imgFil100_1" src="//path..."
              <td>
               <td>
               <img id="imgFil100_2" src="//path..."
              <td>
              <td>
               <img id="imgFil100_3" src="//path..."
              <td>

And i have a lot of buttons in this way "filterXXX". How can i locate them and click on them.

i wrote this code

List<WebElement> lc = driver.findElements(By.cssSelector("table[id*='imgFil']"));
    for (int i = 0; i <= lc.size(); i++) {
     lc.get(i).click();}

BTW Sorry for my english.

Yoz
  • 15
  • 2
  • Your cssSelector is querying `table` elements with an id match. You should perhaps re-write your cssSelector to find all `img` elements with the id match. – Doug Simmons Sep 23 '14 at 22:07
  • List lc = driver.findElements(By.cssSelector("table[id*='filter']")); for (int i = 0; i <= lc.size(); i++) { lc.get(i);driver.findElements(by.WHAT?("[id*='imFill'["); } by What should i find elements? – Yoz Sep 24 '14 at 06:07

1 Answers1

0
List<WebElement> lc = driver.findElements(By.cssSelector("table[id*='filter']"));

for (WebElement row : lc) {
  List<WebElement> images = row.findElements(By.tagName("img"));

  for (WebElement image : images) {
    image.click();
  }
}
Sergii Pozharov
  • 17,366
  • 4
  • 29
  • 30
  • thank you for your help. But i can`t get it to work.no errors.nothing.simply doesn`t find the element – Yoz Sep 25 '14 at 09:31
  • Do you mean that images list is empty? Can you try: List images = row.findElements(By.xpath(".//img")); – Sergii Pozharov Sep 25 '14 at 19:58
  • this is the all hierarchy bottom->up of the page: td[where are the img`s]->tr->table->div->td->tr->table-> table->iframe->form...to be more accurate. Should i change the frame? before locating the element? – Yoz Sep 26 '14 at 08:08
  • yes, you should driver.switchTo().frame to your iframe before finding, and do driver.switchTo().defaultContent(); to get back to the page – Sergii Pozharov Sep 26 '14 at 09:57