使用Selenium从基于JavaScript的表中取消名称
大家好,我正在尝试从基于JavaScript的网站上取出一张桌子。但是,这很奇怪,因为表格分为不同的表标签。我无法在内部服务器上共享网站,但已在下面附加了一些HTML代码:
<div role="presentation" style="position: absolute; left: 0px; top: 0px;">
<div class="dojoxGridRow" role="row" aria-selected="false" idref="admin" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="0" style="width:14em;" hilite="1" fieldname="name">admin</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="locked">
<div class="sprite warning13 mar5r"></div>
Locked
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">08/07/13 07:17:49 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user1" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user1</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="connected">
<div class="sprite checkMark13 mar5r"></div>
Connected (2)
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">07/04/22 03:37:32 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user2" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user2</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">06/27/22 09:55:30 AM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user3" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user3</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">12/18/19 03:56:05 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user4" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user4</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/20/22 05:49:45 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user5" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user5</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/19/22 12:16:31 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user6" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user6</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">07/01/22 03:24:16 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="secadmin" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">secadmin</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="locked">
<div class="sprite warning13 mar5r"></div>
Locked
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="security_admin">Security administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">06/07/21 03:28:40 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="tpcuser" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">tpcuser</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="monitor">Monitor</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">PUBLIC</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">03/03/21 06:00:33 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user6" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user6</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/10/22 12:39:54 PM</td>
</tr>
</tbody>
</table>
</div>
</div>
我的代码:
for i in range(10):
print(i)
Username = driver.find_elements(By.XPATH, value="//*[@id='dojox_grid_View_1']/div/div/div/div[" + str(i) + "]/table/tbody/tr/td[1]")
print(Username)
我对如何正确通过表的XPath如下感到困惑:
admin = //*[@id='dojox_grid_View_1']/div/div/div/div[1]/table/tbody/tr/td[1]
User1 = //*[@id='dojox_grid_View_1']/div/div/div/div[2]/table/tbody/tr/td[1]
User2 = //*[@id='dojox_grid_View_1']/div/div/div/div[3]/table/tbody/tr/td[1]
etc.
我希望输出在列表中,例如
[admin, user1, user2, user3, user4,]
I很抱歉,如果这个问题令人困惑,我会尽力而为
Hello Everyone I am trying to scrap a table from a Javascript based website. It is however quite strange as the table is split up into different table tags. I cannot share the website as its on an internal server but have attached some html code below:
<div role="presentation" style="position: absolute; left: 0px; top: 0px;">
<div class="dojoxGridRow" role="row" aria-selected="false" idref="admin" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="0" style="width:14em;" hilite="1" fieldname="name">admin</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="locked">
<div class="sprite warning13 mar5r"></div>
Locked
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell" idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">08/07/13 07:17:49 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user1" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user1</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="connected">
<div class="sprite checkMark13 mar5r"></div>
Connected (2)
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">07/04/22 03:37:32 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user2" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user2</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">06/27/22 09:55:30 AM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user3" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user3</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">12/18/19 03:56:05 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user4" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user4</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/20/22 05:49:45 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user5" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user5</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/19/22 12:16:31 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="user6" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user6</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">07/01/22 03:24:16 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="secadmin" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">secadmin</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="locked">
<div class="sprite warning13 mar5r"></div>
Locked
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="security_admin">Security administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">06/07/21 03:28:40 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow" role="row" aria-selected="false" idref="tpcuser" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">tpcuser</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="monitor">Monitor</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">PUBLIC</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">03/03/21 06:00:33 PM</td>
</tr>
</tbody>
</table>
</div>
<div class="dojoxGridRow dojoxGridRowOdd" role="row" aria-selected="false" idref="user6" style="">
<table class="dojoxGridRowTable" border="0" cellspacing="0" cellpadding="0" role="presentation">
<tbody>
<tr>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="0" style="width:14em;" hilite="1" fieldname="name">user6</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="1" style="width:12em;" hilite="1" fieldname="state">
<div class="stateCouple userState" data-state="disconnected">
<div class="sprite disabledMark13 mar5r"></div>
Disconnected
</div>
</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="2" style="width:14em;" hilite="1" fieldname="role"><span class="hasMapTooltip" tooltipkey="admin">Administrator</span></td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="3" style="display:none;width:10em;" hilite="1" fieldname="scope">*</td>
<td tabindex="-1" role="gridcell" class="dojoxGridCell " idx="4" style="display:none;width:16em;" hilite="1" fieldname="lastAuthenticatedTime">05/10/22 12:39:54 PM</td>
</tr>
</tbody>
</table>
</div>
</div>
My Code:
for i in range(10):
print(i)
Username = driver.find_elements(By.XPATH, value="//*[@id='dojox_grid_View_1']/div/div/div/div[" + str(i) + "]/table/tbody/tr/td[1]")
print(Username)
I am confused on how to loop through correctly as the table's XPATH are as follows:
admin = //*[@id='dojox_grid_View_1']/div/div/div/div[1]/table/tbody/tr/td[1]
User1 = //*[@id='dojox_grid_View_1']/div/div/div/div[2]/table/tbody/tr/td[1]
User2 = //*[@id='dojox_grid_View_1']/div/div/div/div[3]/table/tbody/tr/td[1]
etc.
I want the output to be in a list e.g.
[admin, user1, user2, user3, user4,]
I am so sorry if this question is confusing, I wrote it as best as I could
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
循环这些表查找第一个TD。
(
表[1:]
将跳过第一个表,这是&lt; th&gt;
的列名称包装)/ -------测试-------------------------------------------- --- /
输出
For loop these tables find first td.
(
tables[1:]
will skip first table which are column names wrap by<th>
)/------test-------/
output