Green eye samurai
Green eye samurai

Reputation: 57

How to take info from particular amount of elements with the same class name?

I have a lot of tables on the same screen. And i need to take tex from only one of it Simple example: Table:Phone

div id="phone_type" type-id="pass" class="panel panel-default sort_table">
      <div class="panel-heading">
        <h3 class="panel-title">PHONE</h3>
      </div>
      <ul class="list-group ui-sortable">
                <li class="list-group-item ui-sortable-handle" id="pass">
      <div class="row">
        <div class="col-md-8 col-xs-8 increase_padding">Home</div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" href="pass">Edit</a>
        </div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" rel="nofollow" data-method="delete" href="pass">Delete</a>
        </div>
      </div>
    </li>
            <li class="list-group-item ui-sortable-handle" id="pass">
      <div class="row">
        <div class="col-md-8 col-xs-8 increase_padding">Work</div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" href="pass">Edit</a>
        </div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" rel="nofollow" data-method="delete" href="pass">Delete</a>
        </div>
      </div>
    </li>
      </ul>

    </form>
      </div>
    </div>

Table:Condo

    <div id="condo_type" type-id="pass" class="panel panel-default sort_table">
      <div class="panel-heading">
        <h3 class="panel-title">CONDO</h3>
      </div>
      <ul class="list-group ui-sortable">
                <li class="list-group-item ui-sortable-handle" id="pass">
      <div class="row">
        <div class="col-md-8 col-xs-8 increase_padding">Limited</div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" href="pass">Edit</a>
        </div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" rel="nofollow" data-method="delete" href="pass">Delete</a>
        </div>
      </div>
    </li>
            <li class="list-group-item ui-sortable-handle" id="pass">
      <div class="row">
        <div class="col-md-8 col-xs-8 increase_padding">Free</div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" href="pass">Edit</a>
        </div>
        <div class="col-md-2 col-xs-2 text-center">
          <a data-remote="true" rel="nofollow" data-method="delete" href="pass">Delete</a>
        </div>
      </div>
    </li>
      </ul>
</form>
  </div>
</div>

And i need to take text of col-md-8 col-xs-8 increase_padding

But the problem is that when i am using:

table_content = driver.find_elements_by_css_selector('.col-md-8.col-xs-8.increase_padding')

it also takes info from tables that i am currently don't need. But i need to take text only from 1 particular table. Those tables are dynamic, so I can't take particular amount from

table_content

and append it to another list. Is it a way to address to particular table and work with its outer HTML?

Upvotes: 0

Views: 59

Answers (1)

alecxe
alecxe

Reputation: 474003

Just make context-specific searches. E.g. If you need this element from a "phone type" table:

phone_type = driver.find_element_by_id("phone_type")
print(phone_type.find_element_by_css_selector('.col-md-8.col-xs-8.increase_padding').text)

Or, in one go:

print(driver.find_element_by_css_selector('#phone_type .col-md-8.col-xs-8.increase_padding').text)

Upvotes: 3

Related Questions