简体   繁体   English

无法使用Selenium Webdriver通过LinkText查找webElement?

[英]Unable to locate webElement by LinkText using selenium webdriver?

Tried every possible way but could not locate the WebElement of WebTable. 尝试了所有可能的方法,但是找不到WebTable的WebElement。 Please find the below HTML excerpt and help me finding the WebElement "Project Costing " : 请找到以下HTML摘录,并帮助我找到WebElement "Project Costing " :

<!DOCTYPE html>
<html class="firefox win pc standard" lang="en" dir="ltr">
<head>
<body class="PSPAGE" onload="loadAllPgltData('portlets',1465250643644);">
<script type="text/javascript">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td>
<table id="ptpglts" width="100%" summary="">
<tbody>
<tr>
<td width="33%" valign="top">
<ul id="ptcol1" class="ptpgltdroppable">
<li id="ptpgltli_MENU" class="pthpli ">
<table id="MENU" class="PTPAGELET" width="100%" cellspacing="0" cellpadding="0" border="0" summary="">
<tbody>
<tr>
<tr id="ptpgltbody_row_MENU">
<td id="ptpgltbody_MENU" class="PTPAGELETBODY" width="100%">
<div id="MENU_Data" class="ptprtlcontainer">
<script id="ptPgltReloadThis" type="text/javascript">
<link type="text/css" href="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PSSTYLEREQ_1.css;wad40e4d39521f1256" rel="stylesheet">
<link type="text/css" href="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PSSTYLEDEF_TANGERINE_4.css;wa90f8b654ed2a321b" rel="stylesheet">
<script type="text/javascript">
<script src="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PT_COMMON_MIN_1.js;waaedd9d526f2073e4" type="text/javascript">
<script src="https://pacefin.techmahindra.com/cs/PACEFIN/cache/PT_AJAX_NET_MIN_1.js;waf370f1177a8f9947" type="text/javascript">
<nav id="ptnav2pglt" aria-label="Menu">
<div id="ptnav2srch">
<div id="ptnav2pgltbody">
<ul id="ptnav2tree">
<li id="MYFAVORITES" class="ptnav2fldr" title="Create a list of frequently used transactions.">
<li id="MANAGE_QUOTE_SYSTEM" class="ptnav2fldr" title="Manage Quotes">
<li id="CO_EMPLOYEE_SELF_SERVICE" class="ptnav2fldr" title="">
<li id="CO_MANAGER_SELF_SERVICE2" class="ptnav2fldr" title="">
<li id="EPCO_CUSTOMERS" class="ptnav2fldr" title="Manage customer information.">
<li id="EPCO_CUSTOMER_CONTRACTS" class="ptnav2fldr" title="Access customer contracts.">
<li id="EPCO_ITEMS" class="ptnav2fldr" title="Manage all item-related options.">
<li id="EPPO_PURCHASING" class="ptnav2fldr" title="Manage requisitions, purchase orders, receipts, GPO contracts, and related data.">
<li id="EPCO_PROGRAM_MANAGEMENT" class="ptnav2fldr" title="Use program management tools to review program progress.">
<li id="EPCO_PROJECTS" class="ptnav2fldr" title="Access project costing.">
<div class="ptnav2toggle"> </div>
<a id="fldra_EPCO_PROJECTS" class="ptntop" href="https://pacefin.techmahindra.com/psp/PACEFIN/EMPLOYEE/ERP/s/WEBLIB_PTPP_SC.HOMEPAGE.FieldFormula.IScript_AppHP?pt_fname=EPCO_PROJECTS&FolderPath=PORTAL_ROOT_OBJECT.EPCO_PROJECTS&IsFolder=true">Project Costing</a>

For any further information regarding above Please ask. 有关以上任何更多信息,请询问。

Try below mentioned xpaths 试试下面提到的xpaths

option 1. //a[text()='Project Costing'] 选项1. //a[text()='Project Costing']

option 2. //*[@id='fldra_EPCO_PROJECTS'] in case this ID value is duplicate then try concatenating it with other attribute like this //*[@id='fldra_EPCO_PROJECTS'][@class='ptntop'] 选项//*[@id='fldra_EPCO_PROJECTS']如果该ID值重复,则尝试将其与其他属性(例如//*[@id='fldra_EPCO_PROJECTS'][@class='ptntop']

option 3. Or start with the table name //table[@id='ptpglts']/a 选项3.或以表名称//table[@id='ptpglts']/a

In case nothing works then try using the xpath sibling methods 如果没有任何效果,请尝试使用xpath兄弟方法

option 4. Use the element just above a step above to your element //*[@class='ptnav2toggle']/following-sibling::a 选项4.在上方的步骤上方使用元素//*[@class='ptnav2toggle']/following-sibling::a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM