ogul ogul - 1 year ago 91
Python Question

Selenium, Python, Can't Click Button by Checking the Table Items Name

I am trying to improve my

skills and for this task, I try to click a button the way that chooses it by table elements name.

For example, in this case, I want to locate
EB Trial 2
then click the
button which is related to that.

<tr ng-repeat="event in bcEvents" class="ng-scope">
<div class="dib fxac">
<i class="icon-event fs32 text-light-blue mr15"></i>
<div class="event-inner">
<a href="" class="link link-underline db ng-binding">EB Trial2</a>
<span class="db fs-small text-light-blue ng-binding">11/15/2016</span>
<td ng-switch="bc_source">
<!-- ngSwitchWhen: 2 --><div ng-switch-when="2" class="ng-scope">
<a href="" ng-click="import_bc_event(event)" class="btn btn-icon btn-orange">
<i class="icon icon-eventbrite-icon"></i> Import
<!-- ngSwitchWhen: 8 -->
<!-- ngSwitchWhen: A -->
<!-- ngSwitchWhen: 9 -->
<!-- ngSwitchWhen: B -->

<!-- ngIf: bc_source != 2 -->

I try to reach it by
but it didn't work

driver.find_element_by_xpath("//td[contains(text(),'EB Trial2')]/preceding-sibling::td[1]").click()

I can't figured it out how to do it

Can anybody help me about this ?

Answer Source

I want to locate EB Trial 2 then click the import button which is related to that

You should try using xpath as :-

driver.find_element_by_xpath(".//td[descendant::a[text()='EB Trial2']]/following-sibling::td//a[normalize-space(.)='Import']
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download