0

Html code is:

<div class="table_body">
  <div>
    <div class="cell" title="Name">Name</div>
    <div class="cell" title="Email" >Email</div>
    <div class="cell" title="Action">Action</div>
  </div>
  <div class="sep_row"></div>
  <div>
    <div class="cell" title="abc">abc</div>
    <div class="cell" title="abc@br.com">abc@br.com</div>
    <div class="fa fa-trash-o"></div>
  </div>
  <div>
     <div class="cell" title="cuser3">cuser3</div>
     <div class="cell" title="auser2@bkr.com">auser2@bkr.com</div>
     <div class="fa fa-trash-o></div>
  </div>
  <div>
     <div class="cell" title="cuser" >cuser</div>
     <div class="cell" title="user@test.com" >user@test.com</div>
     <div class="fa fa-trash-o></div>
  </div>
</div>

How I can get list of emails. Each child element of class="table_body" has different text. In am new in writing selenium test in python.

user2194838
  • 337
  • 2
  • 8
  • 24

1 Answers1

3

To get list of emails try:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("URL")
list_of_elements = driver.find_elements_by_xpath('//div[@class="cell"][contains(@title, "@")]')
emails = [email.text for email in list_of_elements]
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Do you have any idea about When I print these emails its attached u' with every email address – user2194838 Feb 02 '17 at 23:28
  • they're probably in a list.. try using: `listname[0]` – becixb Feb 03 '17 at 05:26
  • @user2194838,this means unicode type string. http://stackoverflow.com/questions/1207457/convert-a-unicode-string-to-a-string-in-python-containing-extra-symbols#answer-1207479 – Andersson Feb 03 '17 at 06:01