无法使用selenium webdriver通过LinkText找到webElement?

时间:2016-06-08 10:30:44

标签: java html selenium

尝试了所有可能的方法,但无法找到WebTable的WebElement。 请找到以下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>

有关上述的任何进一步信息,请询问。

1 个答案:

答案 0 :(得分:1)

尝试下面提到的xpaths

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

选项2. //*[@id='fldra_EPCO_PROJECTS']如果此ID值重复,请尝试将其与其他属性(例如//*[@id='fldra_EPCO_PROJECTS'][@class='ptntop']

连接)

选项3.或者以表名//table[@id='ptpglts']/a

开头

如果没有任何作用,请尝试使用xpath兄弟方法

选项4.将元素正上方的元素用于元素//*[@class='ptnav2toggle']/following-sibling::a