以下是关于我的问题的 HTML ,我在 xpath 中很新...我只是想在c#中创建一个 xpath 其中我将点击时钟和时钟输出按钮。我知道我的问题是基本的,但我很难搞清楚。
这是 HTML
<table>
<tbody>
<tr>
<td><img height="1" src="/images/px.gif" width="10"></td>
<td align="left">
<table cellspacing="4" class="btn" onmousedown=
"return sbtnDown(this);" onmouseout="sbtnOut(this)"
onmouseover="sbtnOver(this)" onmouseup=
"timeSheetAction2("TIME_SHEET_PUNCH","","IN",true)"
width="100%">
<tbody>
<tr>
<td><img src="/images/20x20/clock_go.png"></td>
<td align="left" nowrap width="100%">Clock In</td>
</tr>
</tbody>
</table>
</td>
<td><img height="1" src="/images/px.gif" width="40"></td>
<td align="center">
<table cellspacing="4" class="btn" onclick=
"window.showPopUp_Lookup({"center":1,"w":780,"title":"Change Cost Centres","singleValue":1,"h":800,"url":"/ta/6118466.admin?rnd=EYH&@impl=zeyt.ta.ui.time.UiControl_ChangeCostCenters&@windowId=QLYTJ&Ext=login&sft=PYPBHDQTFA&@showStackMB=0&@pushOnStack=0&@noBG=1&MyLookupName=CHANGE_COST_CENTERS&which_cc_can_change=1","fName":"z230"});return false;"
onmousedown="sbtnDown(this)" onmouseout="sbtnOut(this)"
onmouseover="sbtnOver(this)" width="100%">
<tbody>
<tr>
<td><input name="z230" onchange=
"this.chkChng=0;timeSheetAction2("TIME_SHEET_PUNCH", this.value, "CHANGE_CC", true);"
type="hidden"><img src=
"/images/20x20/clock_refresh.png"></td>
<td align="left" nowrap width="100%">Change Department</td>
</tr>
</tbody>
</table>
</td>
<td><img height="1" src="/images/px.gif" width="40"></td>
<td align="right">
<table cellspacing="4" class="btn" onmousedown=
"sbtnDown(this)" onmouseout="sbtnOut(this)" onmouseover=
"sbtnOver(this)" onmouseup=
"timeSheetAction2("TIME_SHEET_PUNCH","","OUT",true)"
width="100%">
<tbody>
<tr>
<td><img src=
"/images/20x20/clock_cancel.png"></td>
<td align="left" nowrap width="100%">Clock Out</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
以下是我已经尝试但仍然没有运气的方法......
browser.FindElementsByXPath("//td[contains(., 'Clock In')]");
browser.FindElementsByXPath("//id('PAGE_BODY')/x:table[1]/x:tbody/x:tr/x:td[2]/x:table/x:tbody/x:tr/x:td[2]"); #I got this xpath using xpather a firefox plugin
答案 0 :(得分:1)
我认为这应该解决它。
driver.FindElement(By.ClassName("btn")).click(); // For "Clock In"
driver.FindElements(By.ClassName("btn"))[2].click(); // For "Clock Out"
单击时钟输入和时钟输出的表格就足够了,因为它有onmouseup
,onmousedown
等事件。没有必要选择包含文本的td
标记&#34; Clock In&#34;或&#34;时钟输出&#34;。