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>
2

2 Answers 2

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
    
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.