Синтаксис XPATH - Katalon Studio - PullRequest
1 голос
/ 25 июня 2019

Привет, Я хотел получить текст с веб-страницы с Cucumber & Groovy в Katalon Studio.Найдите приведенное ниже определение шага с xpath, а ниже - HTML-код.Я хотел прочитать две строчки ниже со страницы, которые также можно найти в HTML-коде ниже.Число 596 меняется каждый раз, т. Е. Динамически.

Создание отслеживания запроса # 596 Запрос на отслеживание системы # 596 был успешно отправлен

Определение шага queryt1 = WebUI.getText (findTestObject (By.xpath ("// td [@ class = 'pageTitle'] [1]")))

Полный HTML-код страницы:

<html lang="en">
<head>
<title>Govt Inquiry</title>   

<link rel="stylesheet" type="text/css" href="?appId=gmpinquiry&flName=/uitmpl/en/css/uitmpl.css" />
<link rel="stylesheet" type="text/css" href="?appId=gmpinquiry&flName=/gmpinquiry/css/gmpinquiry.css" />
<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/other_scripts.js"></script>
<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/freezingHeader.js"></script>
<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/sortTable.js"></script>
<noscript>
    <style>
        table.mQH {display:block;}
    </style>
</noscript>
<style id="antiClickjack">body{display:none !important;}</style>
<script type="text/javascript">
   if (self === top) {
       var antiClickjack = document.getElementById("antiClickjack");
       antiClickjack.parentNode.removeChild(antiClickjack);
   } else {
       top.location = self.location;
   }
</script>
</head>
<body onload="uitmpl_qhPageInit()">

<!-- Skip To Main Content should be the next element immediately after body element -->
 <div class="skipnav"><a href="#maincontent" title="Skip to Main Content">Skip to Main Content</a> </div>














<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/menu_script.js"></script>
<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/application_settings.js"></script>
<script type="text/javascript" src="?appId=gmpinquiry&flName=/uitmpl/js/global_settings.js"></script>
<script language="javascript">
application.data = {

td_1: "Home",
td_2: "Govt Inquiry",
td_3: "Create Inquiry",
td_4: "Reports/Search",
td_5: "My Preference",

url_1: "javascript:OnGMPPortalSubmit(document.frmMenuScr, '')",
url_2: "javascript:OnMenuSubmit (document.frmMenuScr, 'homepage')",
url_3: "javascript:OnMenuDispatch (document.frmMenuScr, 'setupinquiry','create')",
url_4: "javascript:OnMenuSubmit (document.frmMenuScr, 'inqsubmenu')",
url_5: "javascript:OnMenuSubmit (document.frmMenuScr, 'userpref')"

};

global.data = {
//td_1: "AT&amp;T BusinessDirect",
td_1: "Write Us",
td_2: "Help <span class=\"offscrn\"> - Opens a PDF Document for Help</span>",
td_3: "Close",
//td_3_1: "General Help",
//td_3_2: "Application Tutorial",
//td_3_3: "<span id=\"shHd\">Show</span> Quick Help",
//url_1: "javascript:bizDirect()",
url_1: "javascript:OnMenuSubmit(document.frmMenuScr, 'compose')",
url_2: "javascript:uitmpl_popUpReg(document.frmMenuScr.action + '?appId=' + document.frmMenuScr.appId.value + '&flName=' + document.frmMenuScr.context.value + '/help/Inquiry_UG.pdf')",
url_3: "javascript:window.close();"
//url_3_1: "javascript:uitmpl_popUpReg(document.frmMenuScr.action + \\'?appId=\\' + document.frmMenuScr.appId.value + \\'&flName=\\' + document.frmMenuScr.context.value + \\'/help/Inquiry_UG.pdf\\')",
//url_3_2: "#",
//url_3_3: "javascript:uitmpl_qhPageToggle()"
};
</script>





<script type="text/javascript" src="?appId=gmpinquiry&flName=/gmpinquiry/js/script.js"></script>


<!--************ uitmplbegin: tBAN ************-->
<!--****** begin:background graphic ******-->
<table width="100%" cellspacing="0" border="0" class="tBAN">

    <tr>
        <td><img src="?appId=gmpinquiry&flName=/uitmpl/en/img/swoosh.gif" width="650" height="69" alt="" border="0" /></td>
    </tr>
</table>
<!--****** end:background graphic ******-->

<!--****** begin:logo and company title ******-->
<div class="logoCompany">
<table width="100%" cellspacing="0" border="0" class="tBAN">

    <tr>
        <td class="logo"><img src="?appId=gmpinquiry&flName=/uitmpl/en/img/attbizdirect.gif" width="291" height="63" alt="AT&T | Business Direct" border="0" /></td>
        <td><!-- stretchable cell --></td>
        <!-- max characters for company title: 72 w/ breaks (24 per line) -->
        <td class="company">ATT Gov Sol Dev<br/>rm0013 

      <!-- Begin Skip Top Navigation -->
      <!-- <div class="skipnav"><a href="#main" title="Skip to Main Content">Skip to Main Content</a></div> -->
      <!-- End Skip Top Navigation --></td>
    </tr>
</table>
</div>
<!--****** end:logo and company title ******-->

<!--****** begin:application title ******-->
<table cellspacing="0" border="0" class="appTitle">
    <tr>
        <td><a href="javascript:OnMenuSubmit (document.frmMenuScr, 'homepage')">View and Analyze Govt. Bills: Govt Inquiry</a></td>
    </tr>
</table>
<!--****** end:application title ******-->

<!--************ uitmplend: tBAN ************-->
<!--************ uitmplbegin: tNAV ************-->
<div id="glbl">
<script language="JavaScript1.3">
<!--
uitmpl_list("global");
//-->
</script>
<noscript>
<div class="globalAcc">
<table class="global_main" cellspacing="0" border="0">
<tr>
<td class="global_main_spacer">&nbsp;</td>
<td><a href="javascript:bizDirect()">AT&amp;T BusinessDirect</a></td><td class="pipe">|</td><td><a href="javascript:OnMenuSubmit(document.frmMenuScr, 'compose')" target="_new">Write Us</a></td><td class="pipe">|</td><td><a href="#">Help</a></td>
</tr>
</table>
</div>
</noscript>
</div>
<div id="app">
<script language="JavaScript1.3">
<!--
uitmpl_list("application");
//-->
</script>
<noscript>
<div class="applicationAcc"><table class="application_main" cellspacing="0" border="0">
<tr>
<td><a href="javascript:OnMenuSubmit (document.frmMenuScr, 'homepage')">Home</a></td>
<td class="pipe">|</td>
<td><a href="javascript:alert ('Under Construction...')">Create/Update Dispute</a></td>
<td class="pipe">|</td>
<td><a href="javascript:alert ('Under Construction...')">Reports/Search</a></td>
<td class="pipe">|</td>
<td><a href="javascript:OnMenuSubmit (document.frmMenuScr, 'UserPreference')">My Preference</a></td>
<td class="pipe">|</td>
<td><a href="javascript:alert ('Under Construction...')">User Management</a></td>
</tr>
</table>
</div>
</noscript>
</div>
<!--************ uitmplend: tNAV ************-->
<form name="frmMenuScr" action="/servlet/GMPGate" method="get">
<input type="hidden" name="appId" value="gmpinquiry">
<input type="hidden" name="nextScr" value="userpref">
<input type="hidden" name="methodToCall" value=""/>
<input type="hidden" name="context" value="/gmpinquiry"/>


</form>



<!--***** begin:grid *****-->
<table width="100%" cellspacing="0" border="0" class="wrap">
    <tr>
        <td width="100%" class="grid">
            <!-- InstanceBeginEditable name="PageHeader" -->
            <!--************ uitmplbegin: tPH ************-->
            <!--****** begin:titles ******-->
            <table cellspacing="0" border="0" class="tPH">
                <!--****** begin:page title ******-->
                <tr>
                    <td class="pageTitle">Create Inquiry Tracking # 599</td>
                </tr>
                <!--****** end:page title ******-->
            </table>
            <!--****** end:titles ******-->
            <!--************ uitmplend: tPH ************-->
            <!-- InstanceEndEditable -->
        </td>
        <td width="182" class="grid"><img src="?appId=gmpinquiry&flName=/uitmpl/en/img/pixel.gif" width="182" height="1" alt="" border="0" /></td>
    </tr>
</table>
<!--***** end:grid *****-->

<!--***** begin:grid *****-->
<table width="100%" cellspacing="0" border="0" class="wrap">
    <tr>

<td width="100%" class="grid"> 
<!--- BeginOptional name="TaskConfirmation" --->
<!-- InstanceBeginEditable name="TaskConfirmation" -->
<!--************ uitmplbegin: mTC ************-->
<table cellspacing="0" cellpadding="2" border="0" class="mTC">
<tr class="msgConfirm"> 
<td> <img src="?appId=gmpinquiry&flName=/uitmpl/en/img/confirmation.gif" width="29" height="29" 
        border="0" alt="Confirmation." /></td><td>The inquiry for system tracking # 599 has been submitted successfully. </td>
    </tr>
</table>

ПРИЧИНА ОТКАЗАНО С РЕШЕНИЕМ

2019-06-26 18:40:10.049 ERROR c.k.k.c.c.keyword.CucumberReporter   
- ❌ it should displays create inquiry pages FAILED.

    Reason:
    groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() 
        is applicable for argument types: (org.openqa.selenium.By$ByXPath) values: [By.xpath: //td[@class='pageTitle'][1]]

        Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map) at CreateInquiry001.it_should_displays_create_inquiry_page2(CreateInquiry001.groovy:369)
                at ✽.it should displays create inquiry pages(C:/Users/vdavuluri2/Katalon Studio/Govt Inquiry/Include/features/Create Inquiry-001.feature:55)

Ответы [ 2 ]

0 голосов
/ 27 июня 2019

Метод Каталона findTestObject() используется для выбора объекта из хранилища объектов. Это не работает с By классом.

Вы можете попробовать что-то вроде следующего: создать объект с заданным Xpath и затем использовать WebUI.getText() на нем:

TestObject testObject = new TestObject().addProperty("xpath", ConditionType.EQUALS, "//td[@class='pageTitle'][1]")
WebUI.getText(testObject)
0 голосов
/ 26 июня 2019

Элемент с классом pageTitle выглядит уникальным, так почему бы не пользователь // тд [@ класс = 'PAGETITLE']

...