0

我正在尝试自动化测试其 HTML 是通过 javascript 而不是 Java 呈现的 Web 应用程序。我可以使用 selenium 登录应用程序,因为登录只是一个 HTML 页面。但是一旦我进入应用程序,selenium webdriver 就无法识别 Web 元素。我正在使用 Selenium 2 + Java。我什至尝试将 Web 应用程序保存为 HTML 页面并尝试访问 Web 元素。那里也没有运气。

使用的框架是黄瓜。

package Junit;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;

import testBase.TestBase1;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Feature3StepDef extends TestBase1{
    @Given("^the application is open$")
    public void the_application_is_open() throws Throwable {
        System.setProperty("webdriver.ie.driver", "C:\\Selenium\\IEDriverServer.exe");
        DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); 
          ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
        driver = new InternetExplorerDriver(ieCapabilities);
        driver.get("http://******************/ccb-uata/SPLApp/cis.jsp");
        System.out.println("I am In given");
    }

    @When("^User enters \"([^\"]*)\" and \"([^\"]*)\"$")
    public void User_enters_and(String arg1, String arg2) throws Throwable {
        new WebDriverWait(driver, 50);      
        WebElement user=driver.findElement(By.name("username"));
        System.out.println("element is:" +user);
        user.sendKeys(arg1);
        WebElement psswd = driver.findElement(By.name("password"));
        psswd.sendKeys(arg2);
        WebElement button = driver.findElement(By.name("login"));
        button.click();
        System.out.println("I am In when");
        Thread.sleep(10000);
        WebElement elem = driver.findElement(By.xpath("//*body/div/table[@id='headerTable']"));
        System.out.println("div element: " +elem);
        Thread.sleep(100000);
        System.out.println(arg1);

    }

    @Then("^the application should login$")
    public void the_application_should_login() throws Throwable {
        driver.quit();
        System.out.println("I am In then");
    }

}

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html dir="ltr">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--
    ******************************************************************
    * Program name:      multiSearchNameData
    * Program location:  /ci/controlCentral
    * Program version:   1
    * Program template:  UIXSD
    * Template file:     //Release_Services/release/FW/V2.1.0/splapp/applications/root/WEB-INF/uiXSL/newSearchData.xsl 
    * Template revision: 3
    * Included XSL versions: 
    *   common           
    *   commonGrid       6
    *   commonGrid-xsl   5
    * 
    * Labels:
    *     Table$Field  -  label   (element type, js_name) 
    *     $PER_ACCT_INFO  -  Person/Account   (element type='IL' , jsName='ENTITY_INFO') 
    *     $PREMISE_LBL  -  Premise   (element type='IL' , jsName='PREM_INFO') 
    *     $ID_TYPE_LBL  -  ID Type   (element type='IL' , jsName='ID_TYPE') 
    *     $ID_NBR_LBL  -  ID Nbr   (element type='IL' , jsName='PER_ID_NBR') 
    *     $ACCT_ID  -  Account ID   (element type='HD' , jsName='ACCT_ID') 
    *     $PER_ID  -  Person ID   (element type='HD' , jsName='PER_ID') 
    *     $PREM_ID  -  Premise ID   (element type='HD' , jsName='PREM_ID') 
    * Widget Info:  
    *     Widget_ID , Element Type - label info - label 
    *     SEARCH_RESULTS:x$ENTITY_INFO, IL - $PER_ACCT_INFO -  Person/Account
    *     SEARCH_RESULTS:x$ACCT_INFO, IL
    *     SEARCH_RESULTS:x$PREM_INFO, IL - $PREMISE_LBL -  Premise
    *     SEARCH_RESULTS:x$ID_TYPE, IL - $ID_TYPE_LBL -  ID Type
    *     SEARCH_RESULTS:x$PER_ID_NBR, IL - $ID_NBR_LBL -  ID Nbr
    *     SEARCH_RESULTS:x$ACCT_ID, HD - $ACCT_ID -  Account ID
    *     SEARCH_RESULTS:x$PER_ID, HD - $PER_ID -  Person ID
    *     SEARCH_RESULTS:x$PREM_ID, HD - $PREM_ID -  Premise ID
    *
    ******************************************************************
  -->
<title></title>
<link rel="stylesheet" type="text/css" href="../cisDisabled.css?ltr">
<link rel="stylesheet" type="text/css" href="../cisEnabled.css">
<script type="text/javascript" src="../code/xslListGridSupport.js"></script><script type="text/javascript" src="../code/xslSearchDataSupport.js"></script><script type="text/javascript" src="../code/common.js"></script><script type="text/javascript">
    var isSearchData = true;
    var main = parent.main;
    var searchListModel = parent.searchListModel;

    var searchClient
    // Can go in support, onLoad?
    if (parent.isEmbedded) {
       searchClient = parent.parent
    } else {
       searchClient = parent.opener
    }

    var theListName = 'SEARCH_RESULTS';
    var emptyLine = false;


    var isCSSCompliant = false

    var majorBrowserVersion = navigator.appVersion.match(/MSIE (\d+)/)[1]
    if (majorBrowserVersion < 6){
        isCSSCompliant = false
    }


    var myNavigationKeys = [ 
            'multiSearchNameData'
    ]


    var allFieldPairs = [
        ["xX", "xX", "xX"]

        ]





    function contextKeys() {
      return [
        {jsName: "", altName: "", contextInstance: ""}

      ];
    };



    // cache element types and data class info

var elementMetaData

function initializeElementMetaData() {
    self.elementMetaData = {

            'ENTITY_INFO': {
          jsName: 'ENTITY_INFO',
          elementType: 'IL',
          uiRow: '1',
          uiColumn: '1',
          fieldName: 'PER_ACCT_INFO',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '60'
        },
            'ACCT_INFO': {
          jsName: 'ACCT_INFO',
          elementType: 'IL',
          uiRow: '1',
          uiColumn: '1',
          fieldName: '',
          fieldDataType: '',
          fieldExtendedDataType: '',
          fieldPrecision: ''
        },
            'PREM_INFO': {
          jsName: 'PREM_INFO',
          elementType: 'IL',
          uiRow: '1',
          uiColumn: '2',
          fieldName: 'PREMISE_LBL',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '1'
        },
            'ID_TYPE': {
          jsName: 'ID_TYPE',
          elementType: 'IL',
          uiRow: '1',
          uiColumn: '3',
          fieldName: 'ID_TYPE_LBL',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '1'
        },
            'PER_ID_NBR': {
          jsName: 'PER_ID_NBR',
          elementType: 'IL',
          uiRow: '1',
          uiColumn: '4',
          fieldName: 'ID_NBR_LBL',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '1'
        },
            'ACCT_ID': {
          jsName: 'ACCT_ID',
          elementType: 'HD',
          uiRow: '1',
          uiColumn: '5',
          fieldName: 'ACCT_ID',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '10'
        },
            'PER_ID': {
          jsName: 'PER_ID',
          elementType: 'HD',
          uiRow: '1',
          uiColumn: '6',
          fieldName: 'PER_ID',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '10'
        },
            'PREM_ID': {
          jsName: 'PREM_ID',
          elementType: 'HD',
          uiRow: '1',
          uiColumn: '7',
          fieldName: 'PREM_ID',
          fieldDataType: 'CHAR',
          fieldExtendedDataType: '',
          fieldPrecision: '10'
        }
    }
}

var fkElements
function initializeFKElements(){
    self.fkElements = {

    }
}



// Start Product User exits

// End  Product User exits

</script><!-- Included file '/cm/ext_multiSearchNameData.jsp' not found --></head>
<body onload="loadFunctions();" onkeydown="main.onBodyKeyDown(event, document)" onclick="main.onBodyClick(event, document)">
<div xmlns:clientXSL="temp4" id="headerDivision">
<table id="headerTable" cellpadding="2" cellspacing="0">
<colgroup id="headerColumn1">
<col>
</colgroup>
<colgroup id="headerColumn2">
<col>
</colgroup>
<colgroup id="headerColumn3">
<col>
</colgroup>
<colgroup id="headerColumn4">
<col>
</colgroup>
<colgroup style="display: none;" id="headerColumn5">
<col>
</colgroup>
<colgroup style="display: none;" id="headerColumn6">
<col>
</colgroup>
<colgroup style="display: none;" id="headerColumn7">
<col>
</colgroup>
<thead id="headerTableHead">
<tr class="gridLabel">
<td onclick="clickedSortBy('SEARCH_RESULTS','ENTITY_INFO')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_ENTITY_INFO" name="L_ENTITY_INFO">Person/Account</span><img class="sortImage" src="../images/sortUp.gif" id="SS_ENTITY_INFO" name="SS_ENTITY_INFO"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','PREM_INFO')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_PREM_INFO" name="L_PREM_INFO">Premise</span><img class="sortImage" src="../images/sortUp.gif" id="SS_PREM_INFO" name="SS_PREM_INFO"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','ID_TYPE')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_ID_TYPE" name="L_ID_TYPE">ID Type</span><img class="sortImage" src="../images/sortUp.gif" id="SS_ID_TYPE" name="SS_ID_TYPE"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','PER_ID_NBR')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_PER_ID_NBR" name="L_PER_ID_NBR">ID Nbr</span><img class="sortImage" src="../images/sortUp.gif" id="SS_PER_ID_NBR" name="SS_PER_ID_NBR"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','ACCT_ID')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_ACCT_ID" name="L_ACCT_ID">Account ID</span><img class="sortImage" src="../images/sortUp.gif" id="SS_ACCT_ID" name="SS_ACCT_ID"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','PER_ID')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_PER_ID" name="L_PER_ID">Person ID</span><img class="sortImage" src="../images/sortUp.gif" id="SS_PER_ID" name="SS_PER_ID"></span></td><td onclick="clickedSortBy('SEARCH_RESULTS','PREM_ID')" style="cursor:hand" nowrap valign="middle" class="gridTd"><span>&nbsp;<span id="L_PREM_ID" name="L_PREM_ID">Premise ID</span><img class="sortImage" src="../images/sortUp.gif" id="SS_PREM_ID" name="SS_PREM_ID"></span></td>
</tr>
</thead>
</table>
</div>
<script type="text/javascript">
    var _clientXSL;
    function templateRow(){
      if (_clientXSL) return _clientXSL;


      _clientXSL = '\x3CclientXSL\x3Atemplate\x20match\x3D\x22\x2F\x22\x3E\x3CclientXSL\x3Avariable\x20name\x3D\x22startUIIndex\x22\x3E\x3CclientXSL\x3Achoose\x3E\x3CclientXSL\x3Awhen\x20test\x3D\x22\x2Flist\x2FstartUIIndex\x2F\x40value\x22\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x2Flist\x2FstartUIIndex\x2F\x40value\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2FclientXSL\x3Awhen\x3E\x3CclientXSL\x3Aotherwise\x3E0\x3C\x2FclientXSL\x3Aotherwise\x3E\x3C\x2FclientXSL\x3Achoose\x3E\x3C\x2FclientXSL\x3Avariable\x3E\x3CclientXSL\x3Avariable\x20name\x3D\x22oddEvenOffset\x22\x3E\x3CclientXSL\x3Achoose\x3E\x3CclientXSL\x3Awhen\x20test\x3D\x22\x2Flist\x2FstartOnOddRow\x2F\x40value\x3D\x27true\x27\x22\x3E1\x3C\x2FclientXSL\x3Awhen\x3E\x3CclientXSL\x3Aotherwise\x3E0\x3C\x2FclientXSL\x3Aotherwise\x3E\x3C\x2FclientXSL\x3Achoose\x3E\x3C\x2FclientXSL\x3Avariable\x3E\x3Ctable\x20onkeypress\x3D\x22handleTRKeyPress\x28\x29\x22\x20onkeydown\x3D\x22handleTRKeyDown\x28\x29\x22\x20id\x3D\x22dataTable\x22\x20cellpadding\x3D\x222\x22\x20cellspacing\x3D\x220\x22\x3E\x3Ccolgroup\x20id\x3D\x22dataColumn1\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20id\x3D\x22dataColumn2\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20id\x3D\x22dataColumn3\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20id\x3D\x22dataColumn4\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20style\x3D\x22display\x3A\x20none\x3B\x22\x20id\x3D\x22dataColumn5\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20style\x3D\x22display\x3A\x20none\x3B\x22\x20id\x3D\x22dataColumn6\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Ccolgroup\x20style\x3D\x22display\x3A\x20none\x3B\x22\x20id\x3D\x22dataColumn7\x22\x3E\x3Ccol\x3E\x3C\x2Fcol\x3E\x3C\x2Fcolgroup\x3E\x3Cthead\x20id\x3D\x22dataTableHead\x22\x3E\x3Ctr\x20style\x3D\x22visibility\x3A\x20hidden\x3B\x20height\x3A\x200\x25\x3B\x20position\x3A\x20absolute\x3B\x22\x20height\x3D\x220\x22\x20class\x3D\x22gridLabel\x22\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27ENTITY\x5FINFO\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FENTITY\x5FINFO\x22\x20name\x3D\x22D\x5FL\x5FENTITY\x5FINFO\x22\x3EPerson\x26\x23x2F\x3BAccount\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FENTITY\x5FINFO\x22\x20name\x3D\x22D\x5FSS\x5FENTITY\x5FINFO\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27PREM\x5FINFO\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FPREM\x5FINFO\x22\x20name\x3D\x22D\x5FL\x5FPREM\x5FINFO\x22\x3EPremise\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FPREM\x5FINFO\x22\x20name\x3D\x22D\x5FSS\x5FPREM\x5FINFO\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27ID\x5FTYPE\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FID\x5FTYPE\x22\x20name\x3D\x22D\x5FL\x5FID\x5FTYPE\x22\x3EID\x20Type\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FID\x5FTYPE\x22\x20name\x3D\x22D\x5FSS\x5FID\x5FTYPE\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27PER\x5FID\x5FNBR\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FPER\x5FID\x5FNBR\x22\x20name\x3D\x22D\x5FL\x5FPER\x5FID\x5FNBR\x22\x3EID\x20Nbr\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FPER\x5FID\x5FNBR\x22\x20name\x3D\x22D\x5FSS\x5FPER\x5FID\x5FNBR\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27ACCT\x5FID\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FACCT\x5FID\x22\x20name\x3D\x22D\x5FL\x5FACCT\x5FID\x22\x3EAccount\x20ID\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FACCT\x5FID\x22\x20name\x3D\x22D\x5FSS\x5FACCT\x5FID\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27PER\x5FID\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FPER\x5FID\x22\x20name\x3D\x22D\x5FL\x5FPER\x5FID\x22\x3EPerson\x20ID\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FPER\x5FID\x22\x20name\x3D\x22D\x5FSS\x5FPER\x5FID\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20onclick\x3D\x22clickedSortBy\x28\x27SEARCH\x5FRESULTS\x27\x2C\x27PREM\x5FID\x27\x29\x22\x20style\x3D\x22cursor\x3Ahand\x22\x20nowrap\x3D\x22nowrap\x22\x20valign\x3D\x22middle\x22\x20class\x3D\x22gridTd\x22\x3E\x3Cspan\x3E \x3Cspan\x20id\x3D\x22D\x5FL\x5FPREM\x5FID\x22\x20name\x3D\x22D\x5FL\x5FPREM\x5FID\x22\x3EPremise\x20ID\x3C\x2Fspan\x3E\x3Cimg\x20class\x3D\x22sortImage\x22\x20src\x3D\x22\x2E\x2E\x2Fimages\x2FsortUp\x2Egif\x22\x20id\x3D\x22D\x5FSS\x5FPREM\x5FID\x22\x20name\x3D\x22D\x5FSS\x5FPREM\x5FID\x22\x3E\x3C\x2Fimg\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3C\x2Ftr\x3E\x3C\x2Fthead\x3E\x3Ctbody\x20id\x3D\x22dataTableBody\x22\x3E\x3CclientXSL\x3Afor\x2Deach\x20select\x3D\x22\x2Flist\x2Felement\x22\x3E\x3Ctr\x20onclick\x3D\x22handleTRClick\x28\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x29\x22\x20uiRowIndex\x3D\x22\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x3CclientXSL\x3Achoose\x3E\x3CclientXSL\x3Awhen\x20test\x3D\x22\x28position\x28\x29\x20\x2B\x20\x24oddEvenOffset\x29\x20mod\x202\x20\x3D\x200\x22\x3EgridAlt\x3C\x2FclientXSL\x3Awhen\x3E\x3CclientXSL\x3Aotherwise\x3Egrid\x3C\x2FclientXSL\x3Aotherwise\x3E\x3C\x2FclientXSL\x3Achoose\x3E\x3C\x2FclientXSL\x3Aattribute\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ENTITY\x5FINFO\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ENTITY\x5FINFO\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D60\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x40ENTITY\x5FINFO\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2Fspan\x3E\x3Cdiv\x20style\x3D\x22margin\x2Dleft\x3A\x203\x20ex\x3B\x22\x3E\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ACCT\x5FINFO\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ACCT\x5FINFO\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x40ACCT\x5FINFO\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2Fspan\x3E\x3C\x2Fdiv\x3E\x3C\x2Ftd\x3E\x3Ctd\x20width\x3D\x22350\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PREM\x5FINFO\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PREM\x5FINFO\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D1\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x40PREM\x5FINFO\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ID\x5FTYPE\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ID\x5FTYPE\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D1\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x40ID\x5FTYPE\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PER\x5FID\x5FNBR\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PER\x5FID\x5FNBR\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D1\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Avalue\x2Dof\x20select\x3D\x22\x40PER\x5FID\x5FNBR\x22\x3E\x3C\x2FclientXSL\x3Avalue\x2Dof\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ACCT\x5FID\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24ACCT\x5FID\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x20display\x3A\x20none\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D10\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PER\x5FID\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PER\x5FID\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x20display\x3A\x20none\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D10\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3Ctd\x20id\x3D\x22SEARCH\x5FRESULTS\x7C\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x22\x20valign\x3D\x22middle\x22\x20align\x3D\x22\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3E\x20gridTd\x3C\x2FclientXSL\x3Aattribute\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22nowrap\x22\x3Enowrap\x3C\x2FclientXSL\x3Aattribute\x3E\x26\x23xa0\x3B\x3Cspan\x20name\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PREM\x5FID\x22\x20id\x3D\x22SEARCH\x5FRESULTS\x3A\x7Bposition\x28\x29\x20\x2D\x201\x20\x2B\x20\x24startUIIndex\x7D\x24PREM\x5FID\x22\x20style\x3D\x22margin\x2Dright\x3A\x200\x2E20\x20em\x3B\x20display\x3A\x20none\x3B\x22\x3E\x3CclientXSL\x3Aattribute\x20name\x3D\x22class\x22\x3Edata\x20dc\x2DCHAR\x2DNONE\x2D10\x2D0\x20\x3C\x2FclientXSL\x3Aattribute\x3E\x3C\x2Fspan\x3E\x3C\x2Ftd\x3E\x3C\x2Ftr\x3E\x3C\x2FclientXSL\x3Afor\x2Deach\x3E\x3C\x2Ftbody\x3E\x3C\x2Ftable\x3E\x3C\x2FclientXSL\x3Atemplate\x3E'

    // wrap template row with stylesheet
    _clientXSL = ' <clientXSL:stylesheet  xmlns:clientXSL="http://www.w3.org/1999/XSL/Transform" version="1.0">\n'
                   + '<clientXSL:output method="html" encoding="UTF-8"/>\n'
                   + _clientXSL + '\n</clientXSL:stylesheet>'


      return _clientXSL;
    }

    var listName = 'SEARCH_RESULTS';
   </script><span style="position:absolute;"><img src="../images/expandScroll.gif" id="scrollControl" name="scrollControl" style="position:absolute; top:-17px; right:-1px; visibility:hidden;"><div id="dataDivision" onscroll="onTableScroll();"></div>
</span>
<iframe scrolling="auto" id="context" src="../blankEmpty.html" class="contextMenu" frameborder="0" width="1" height="1"></iframe>
</body>
</html>

错误:org.openqa.selenium.TimeoutException:等待 100 秒后超时,等待位于以下位置的元素存在:By.xpath:* [@id='headerDivision'] 构建信息:版本:'2.32.0',修订:' 6c40c18', 时间: '2013-04-09 17:23:22' 系统信息: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1',​​ java.version: ' 1.6.0_27' 驱动程序信息:driver.version:在 org.openqa.selenium.support.ui.FluentWait.timeoutException(FluentWait.java:259) 在 org.openqa.selenium.support.ui.FluentWait.until(FluentWait. java:228) at Junit.Feature3StepDef.User_enters_and(Feature3StepDef.java:53) at ?.When User enters "syahm" and "Powerful4"(Resources\Features\Feature3.feature:5) 原因:org.openqa.selenium。 NoSuchElement异常:Unable to find element with xpath == *[@id='headerDivision'](警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:343 毫秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html 构建信息:版本:'2.32.0',修订:'6c40c18',时间:'2013-04-09 17:23:22' 系统信息:os.name : 'Windows XP', os.arch: 'x86', os.version: '5.1',​​ java.version: '1.6.0_27' 会话 ID: bb4475ec-3408-43f3-a7d2-22e2c0b94b66 驱动程序信息: org.openqa。 selenium.ie.InternetExplorerDriver 功能 [{platform=WINDOWS, javascriptEnabled=true, cssSelectorsEnabled=true, handlesAlerts=true, browserName=internet explorer, nativeEvents=true, takeScreenshot=true, version=7}]

4

1 回答 1

0

等待时间

Selenium 只与 DOM 交互,所以我们不关心背后的代码。就呈现的 html 而言,这可能是时间问题。在调试模式下运行测试并在测试开始处放置一个断点。然后在页面有时间加载后手动逐步完成每个步骤。

如果是时间问题,您可以执行以下两项操作之一:

  1. 通过检查文档就绪状态等待页面加载。 是执行此操作的 C# 方法。
  2. 您的第二个选择是等待您正在寻找的元素出现。您可以在另一个问题中看到一个很好的例子。

这是该帖子的建议:

WebElement foundElement = new WebDriverWait(webdriver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.Id("myId")));

选择器

如果不是等待时间,则可能是选择器不正确,并且您没有抓住正确的元素。XPath 是解决这个问题的最简单方法。

  1. 在 Chrome 中打开页面
  2. 右键单击元素并选择检查元素
  3. Chrome 应该显示 html 并且您应该在该元素上。右键单击并复制 XPath
  4. 将选择器更改为driver.FindElement(By.XPath("selector you just found")); 请注意,您可能需要稍微调整一下,以免转义引号。
  5. 在 Chrome 中使用新的选择器再次运行。如果它不起作用,请在选择它之前暂停并再次搜索 XPath,并将之前的内容与现在的内容进行比较。
于 2013-09-16T22:56:53.703 回答