1

I want to get some td data from dynamic table with selenium and push them in array. I tried to use:

driver.find_elements_by_class_name("row_data")

and get the html then find td but the list element can't get attribute innerHTML ...

<tr class="row_data text-silver">
                <td class="link">
                        <a href="/Account/UserCompleteRegister" data-toggle="tooltip" data-placement="left" title="ویرایش" class="btn btn-info btn-xs btnEditUser">
                            <i class="fa fa-edit"></i>
                        </a> 
مرضیه<input type="hidden" value="1332162477" class="userId">
                </td>
<td class="text-right">
ایرج ساعی 

</td>
<td class="text-right">
6180033005  

</td>
<td class="text-right">


</td>
<td class="text-right">
25 سال و 2 روز    

</td>
<td class="text-right">

<span class="GenderText">زن</span>


</td>
</tr>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Pablo
  • 561
  • 4
  • 16
  • 2
    Does this answer your question? [Iterate through table rows and print column text with Python Selenium](https://stackoverflow.com/questions/31812537/iterate-through-table-rows-and-print-column-text-with-python-selenium) – Sariq Shaikh Mar 22 '20 at 10:58
  • try ```driver.find_elements_by_class_name("row_data.text-silver")```, space become dot. BTW for web scrapping tables i would recommend using ```pandas.read_html```. – ofeksr Mar 22 '20 at 11:18

2 Answers2

1

A bit of more information with respect to which data you are exactly looking for would have helped us to construct the answer in a canonical way. However as the class attribute of the <tr> node contains row_data and text-silver you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "tr.row_data.text-silver))).text)
    
  • Using XPATH:

    print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//tr[@class='row_data text-silver']"))).text)
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

If its single table on your page and you want to use xpath then please refer below solution :

1.  //table//td[*]      
2.  //table//tr//td[*]

or else provide specific table id to handle your tabel

SeleniumUser
  • 4,065
  • 2
  • 7
  • 30