我正在使用以下代码查找并点击网址。我在网页上有多个链接。我需要找到我想要的URL并单击它。为了完成这项任务,我将我的部分字符串存储在'urlname'变量中并在下面的示例中使用它:
driver.FindElement(By.PartialLinkText(urlname)).Click();
但上面的代码没有做任何事情。它甚至没有找到元素而不是点击它。请帮助。
以下是HTML代码:
<table xmlns:downloader="http://schemas.niku.com/java/com.niku.dms.web.ZipPageDownloader" border="0" cellspacing="1" cellpadding="2" class="tableGridList" width="100%">
<tbody>
<tr class="TableGridList"><td class="ColHeadNoSort" scope="col"><a href="javascript:checkAllOver('dms.fileManager');"><img src="ui/evolution1/images/IcoCheckAll.gif" border="0" alt="Check All" title="Check All"></a></td><td class="ColHeadNoSort" colspan="3" align="center" scope="col">Name</td><td class="ColHeadNoSort" align="center" scope="col"> </td><td class="ColHeadNoSort" scope="col">Size</td><td class="ColHeadNoSort" scope="col">Type</td><td class="ColHeadNoSort" scope="col">Status</td><td class="ColHeadNoSort" scope="col">Modified</td><td class="ColHeadNoSort" scope="col">Actions</td></tr>
<tr valign="top" class="rowOff" onmouseover="this.className='rowOn'" onmouseout="this.className='rowOff'"><td valign="middle" align="center" width="20" scope="row"> </td><td valign="middle" width="20" class="hierTee"><img src="ui/evolution1/images/Spacer.gif" height="16" width="16" border="0" alt=""></td><td valign="middle"><img src="ui/evolution1/images/fmFolderClosed.gif" alt="" title=""></td><td valign="middle" width="100%"><a class="tableLink" target="" href="app?action=dms.ProjectsfileManager&folderId=5697033&returnAction=dms.ProjectsFileManager&cancelAction=dms.ProjectsFileManager&actionItemId=&id=5103184&type=Projects&taskID=&fromPage=&rootFolderId=&">Great India's place</a></td><td valign="middle" align="left" nowrap="true" id="PPP"></td><td valign="middle" align="left" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="center" nowrap="true">9/26/15 8:27 PM</td><td valign="middle" align="right"><select name="folder5697033" onchange="optionGoTo( this.form.name,'folder5697033')" class="docMgrAction"><option value=""></option></select></td></tr>
<tr valign="top" class="rowOff" onmouseover="this.className='rowOn'" onmouseout="this.className='rowOff'"><td valign="middle" align="center" width="20" scope="row"> </td><td valign="middle" width="20" class="hierTee"><img src="ui/evolution1/images/Spacer.gif" height="16" width="16" border="0" alt=""></td><td valign="middle"><img src="ui/evolution1/images/fmFolderClosed.gif" alt="" title=""></td><td valign="middle" width="100%"><a class="tableLink" target="" href="app?action=dms.ProjectsfileManager&folderId=5687045&returnAction=dms.ProjectsFileManager&cancelAction=dms.ProjectsFileManager&actionItemId=&id=5103184&type=Projects&taskID=&fromPage=&rootFolderId=&">India's silver gold awards</a></td><td valign="middle" align="left" nowrap="true" id="PPP"></td><td valign="middle" align="left" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="center" nowrap="true">8/6/15 12:04 PM</td><td valign="middle" align="right"><select name="folder5687045" onchange="optionGoTo( this.form.name,'folder5687045')" class="docMgrAction"><option value=""></option></select></td></tr>
<tr valign="top" class="rowOff" onmouseover="this.className='rowOn'" onmouseout="this.className='rowOff'"><td valign="middle" align="center" width="20" scope="row"> </td><td valign="middle" width="20" class="hierTee"><img src="ui/evolution1/images/Spacer.gif" height="16" width="16" border="0" alt=""></td><td valign="middle"><img src="ui/evolution1/images/fmFolderClosed.gif" alt="" title=""></td><td valign="middle" width="100%"><a class="tableLink" target="" href="app?action=dms.ProjectsfileManager&folderId=5693965&returnAction=dms.ProjectsFileManager&cancelAction=dms.ProjectsFileManager&actionItemId=&id=5103184&type=Projects&taskID=&fromPage=&rootFolderId=&">India's Gold awards</a></td><td valign="middle" align="left" nowrap="true" id="PPP"></td><td valign="middle" align="left" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="center" nowrap="true">9/8/15 10:02 AM</td><td valign="middle" align="right"><select name="folder5693965" onchange="optionGoTo( this.form.name,'folder5693965')" class="docMgrAction"><option value=""></option></select></td></tr>
<tr valign="top" class="rowOff" onmouseover="this.className='rowOn'" onmouseout="this.className='rowOff'"><td valign="middle" align="center" width="20" scope="row"> </td><td valign="middle" width="20" class="hierTee"><img src="ui/evolution1/images/Spacer.gif" height="16" width="16" border="0" alt=""></td><td valign="middle"><img src="ui/evolution1/images/fmFolderClosed.gif" alt="" title=""></td><td valign="middle" width="100%"><a class="tableLink" target="" href="app?action=dms.ProjectsfileManager&folderId=5691948&returnAction=dms.ProjectsFileManager&cancelAction=dms.ProjectsFileManager&actionItemId=&id=5103184&type=Projects&taskID=&fromPage=&rootFolderId=&">Awards night - India</a></td><td valign="middle" align="left" nowrap="true" id="PPP"></td><td valign="middle" align="left" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="right" nowrap="true"></td><td valign="middle" align="center" nowrap="true">8/28/15 7:30 AM</td><td valign="middle" align="right"><select name="folder5691948" onchange="optionGoTo( this.form.name,'folder5691948')" class="docMgrAction"><option value=""></option></select></td></tr>
</tbody>
</table>
我想点击链接“印度的金奖”。我在变量'urlname'中存储了“金奖”字符串。