ogul ogul - 1 month ago 14
Python Question

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

I am trying to improve my

Selenium
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
import
button which is related to that.

<tr ng-repeat="event in bcEvents" class="ng-scope">
<td>
<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>
</div>
</div>
</td>
<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
</a>
</div>
<!-- ngSwitchWhen: 8 -->
<!-- ngSwitchWhen: A -->
<!-- ngSwitchWhen: 9 -->
<!-- ngSwitchWhen: B -->
</td>

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


I try to reach it by
XPath
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

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']
Comments