【发布时间】:2015-01-02 20:01:48
【问题描述】:
我正在编写一个脚本来定位/单击一个下拉列表,然后使用 selenium 和 python 从所选下拉列表中单击任何项目。
下面是代码,如果它正确,希望您的帮助使它变得更好,如果它不正确的方法,请纠正它。
代码片段:
table1 = self.browser.find_element_by_id('user-list-table')
trows = table1.find_elements_by_tag_name('tr')
for trow in trows:
tcols = trow.find_element_by_tag_name('td')
for tcol in tcols:
if tcol ==("//button[@id='dropdownMenu1'][3]"):
self.browser.find_element_by_xpath(tcol).click()
self.browser.find_element_by_link("//a[contains(text(),'Edit User')][3]").click()
HTML sn-p:
<table class="table table-bordered table-striped datatable" id="user-list-table">
<thead>
<tr>
<th>Status</th>
<th>First Name</th>
<th>Last Name</th>
<th>Employee ID</th>
<th>Patient Load<br>Permanent | Temporary</th>
<th>No. of Tasks<br>Priority | Total</th>
<th>Tasks Per Day (completed)<br>Week | Month | Quarter</th>
<th class="text-right">User Actions</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td class="text-center"><i class="status status-available">01</i></td>
<td>Tracy</td>
<td>Jones</td>
<td>1001</td>
<td>10 | 5</td>
<td>30 | 50</td>
<td>45 | 60 | 50</td>
<td class="text-right">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
User Actions
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu">
<li role="presentation"><a role="menuitem" tabindex="-1" href="patient-assignment.html"><i class="fa fa-exchange"></i> Assign Patients</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" data-toggle="modal" data-target="#User-Calendar-Today"><i class="fa fa-calendar"></i> Todays Availability</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="user-profile.html"><i class="fa fa-user"></i> View Profile</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="user-account.html"><i class="fa fa-pencil"></i> Edit User</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#"><i class="fa fa-times-circle"></i> Deactivate User</a></li>
</ul>
</div>
</td>
</tr>
【问题讨论】:
-
我的 HTML 文件太长,无法在此处发布。有没有其他分享方式。
-
jsfiddle在这里jsfiddle.net
-
jsfiddle.net/n5evsaof/3。请让我知道这是否有帮助
-
错误是什么?您似乎没有点击正确的链接吗?
标签: python python-2.7 selenium selenium-webdriver