2014-03-04 37 views
0

我想從基於它的id屬性使用硒的表單中選擇特定的文本框。Selenium <textbox>嵌套在<table td>

我試過下面的代碼,但它顯示「無法找到id ...」錯誤。

WebDriverWait waitt = new WebDriverWait(driver, 120); 
waitt.until(ExpectedConditions.visibilityOfElementLocated(By.id("leadCaptureList_leadCapture_firstName"))); 

WebElement query = driver.findElement(By.xpath("//* [@id='leadCaptureList_leadCapture_firstName']"));` 

而且我也試過像WebElement textbox = driver.findElement(By.id("leadCaptureList_leadCapture_firstName"));但仍然沒有運氣。

硒中是否有任何選擇嵌套文本框元素?

http://my.jetscreenshot.com/demo/20140304-c1dk-105kb.jpg(按CTRL +放大圖像) 這裏(在圖像中)是我的頁面的html結構。 在這張圖片中,我突出顯示了我試圖定位的文本框。如建議在評論下方

<table id="page-container" border="0" cellpadding="0" cellspacing="0" width="100%"> 

<tbody><tr> 
    <td id="page-header"> 

<div id="top"> 

<div id="page-title" class="limiter clear-block"> 

<div id="header-top"> 

<div id="logo"><img id="logo-image" alt="Home" src="images/logo.png"></div> 

<div id="header-right"> 

<div id="block-ad" class="block block-ad"> 

<div class="block-content clear-block "> 



</div> 

</div> 



<div id="header-links"> 

<!-- added table for structure --> 

<table style="display:block; float:right;" class="norubik" border="0" cellpadding="1" cellspacing="0" width="100%"> 

<tbody><tr> 

<td align="center"><font color="#666"><a href="/user" style="color: red;font-size:10px;font-family:Verdana;color:#666;text-decoration: none">My Account </a> | <a style="color: red;font-size:10px;font-family:Verdana;color:#666;text-decoration: none" href="/logout">Logout</a></font></td> 

</tr> 

<tr> 

<td align="center"> 

<span class="username"><!--Logged in as--> <strong>admin</strong> 

<!-- Code for image --> 

<div style="position:relative; top:2px; left:0px;"> 





    <img src="images/premier_small.png"> 







</div> 

</span> 

</td> 

</tr> 

</tbody></table> 

</div> 









</div> 

</div> 

<div style="width: 100%; clear: both; text-align: left; margin-bottom: 6px; height:30px;"> 


<!-- begin menu div --> 

<div class="AJXCSSMenuGdPbSLD"><!-- AJXFILE:ajxmenu.css --> 

<div class="ajxmw"> 

<div class="ajxmw2"> 

<ul> 



    <li style="position: static;" class=""><a class="ajxsub" href="/" title="Home"><b>Home</b> 

    </a> 

    <div style="display: none;" class="ajxdd"> 

    <div class="ajxsbg"> 



    </div> 

    </div> 

    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/node/3111" title="Getting Started"><b>Getting Started</b> 

    </a> 


    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/node/2962" title="Training"><b>Training</b> 

    </a> 

    <div style="display: none;" class="ajxdd"> 

    <div class="ajxsbg"> 



    <ul> 



     <li style="position: static;" class=""><a class="ajxsub" href="/faq" title="FAQ">FAQ</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3431" title="Video Tutorials">Video Tutorials</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3138" title="Training Webinars">Training Webinars</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/pub/training-schedule" title="Training Schedule">Training Schedule</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3735" title="Internet Marketing Webinars">Internet Marketing Webinars</a></li> 



    </ul> 



    </div> 

    </div> 

    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/reseller/ir/leadCaptureList" title="Leads"><b>Leads</b> 

    </a> 
    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/node/2964" title="Affiliate"><b>Affiliate</b> 

    </a> 

    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/catalog/179" title="Store"><b>Store</b> 

    </a> 

    <div style="display: none;" class="ajxdd"> 

    <div class="ajxsbg"> 



    <ul> 



     <li style="position: static;" class=""><a class="ajxsub" href="/catalog/179" title="Memberships">Memberships</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/catalog/219" title="Marketplace">Marketplace</a></li> 



    </ul> 



    </div> 

    </div> 

    </li> 



    <li style="position: static;" class=""><a class="ajxsub" href="/" title="Resources"><b>Resources</b> 

    </a> 

    <div style="display: none;" class="ajxdd"> 

    <div class="ajxsbg"> 



    <ul> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3017" title="Support">Support</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/reseller/calendar" title="Calendar/Events">Calendar/Events</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3440" title="Documents">Documents</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/17" title="Documents">Documents</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/reseller/ir/contactInfo" title="Upline Report">Upline Report</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3353" title="Feature Comparison">Feature Comparison</a></li> 



     <li style="position: static;" class=""><a class="ajxsub" href="/node/3497" title="Developer (API)">Developer (API)</a></li> 



    </ul> 



    </div> 

    </div> 

    </li> 







</ul> 

</div> 

</div> 

</div> 

<!-- end menu div --></div> 

</div> 



<div id="branding"> 

<div class="limiter clear-block"> 

<div class="breadcrumb clear-block"><span class="breadcrumb-link"><a href="/">LeadOutcome</a></span> <span class="breadcrumb-link"><a href="leadCaptureList.action">Leads</a></span> <span class="breadcrumb-link"><a href="leadCaptureList.action">Manage Leads</a></span> </div> 

</div> 

</div> 

</div> 






    </td> 
    </tr> 


    <tr> 
    <td id="content-container"> 

     <div id="page" class="clear-block page-content"> 

    <div id="content"> 
     <div class="content-wrapper clear-block"> 

<table border="0" cellpadding="0" cellspacing="0" width="100%"> 
    <tbody><tr> 
     <td class="bhdr-container"><span class="bhdr"> Manage Leads </span></td> 
    </tr> 
</tbody></table> 
<span style="color: blue; font-weight: bold"></span> 
<span style="color: red; font-weight: bold"></span> 


<form id="leadCaptureList" name="leadCaptureList" action="leadCaptureList.action" method="post"> 
<div><input name="advanceSearchClicked" value="No" id="advanceSearchClicked" type="hidden"> 

    </div><table class="wwFormTable"> 
    <input name="leadsToTransfer" value="" id="leadsToTransferId" type="hidden"> 
    <input name="deleteids" value="" id="leadCaptureList_deleteids" type="hidden"> 
    <input name="leadOrIR" value="Lead" id="leadCaptureList_leadOrIR" type="hidden"> 
    <input name="savedSearchCriteria.searchName" value="" id="leadCaptureList_savedSearchCriteria_searchName" type="hidden"> 
    <input name="savedSearchCriteria.published" value="" id="leadCaptureList_savedSearchCriteria_published" type="hidden"> 
    <input name="leadSearchName" value="" id="leadCaptureList_leadSearchName" type="hidden"> 
    <input name="cfValuesFromSessOrDB" value="false" id="leadCaptureList_cfValuesFromSessOrDB" type="hidden"> 

    </table><table class="hdr-section-search" border="0" cellpadding="0" cellspacing="0"> 
     <tbody><tr> 
      <td>&nbsp;</td> 
     </tr> 
     <tr> 
      <td> 
      <table style="background-color: #F8F8F8" class="conbox4" border="0" cellpadding="2" cellspacing="0" width="100%"> 
       <tbody><tr> 

        <th colspan="4"><font size="2">Search Options (Search criteria can be combined)</font></th> 
        <th colspan="6" align="right"> 
         <select id="currentlyOwnedLeads" name="currentlyOwnedLeads"> 

          <option value="All">All leads </option> 

          <option value="No">Show all leads ever owned by me </option> 
          <option value="Yes">Show only leads currently owned by me </option> 
         </select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
         <input name="" value="All" id="currentlyOwnedIdUsedForJavascript" type="hidden"> 
        <input name="coForManageLeads" id="selectedSalesRepCo" value="" type="hidden"> 
        <input name="id" value="" id="leadCaptureList_id" type="hidden"> Sales Rep: <span id="selectedIrCompany"></span> <a href="javascript:void()" id="searchIrButton"><img src="images/btn_find_IR.png" border="0"></a></th> 

        <th colspan="3" align="center"> 
        <span onmousemove="ddrivetip(receiveSummaryMouseover,150)" onmouseout="hideddrivetip()">Receive Lead Summary:<select name="receiveLeadManagementSummaryEmails" id="summaryMailsField" onchange="setReceiveLeadManagementSummaryEmails();"> 
    <option value="false">No</option> 
    <option value="true" selected="selected">Yes</option> 


</select> 
</span> 
        </th> 
       </tr> 


       <tr> 
        <td align="right">Lead Id:</td> 
        <td><input name="leadIdForSearch" maxlength="7" value="" id="leadCaptureList_leadIdForSearch" style="width:80px" type="text"></td> 
        <td align="right">First Name:</td> 
        <td><input name="leadCapture.firstName" value="test Lo" id="leadCaptureList_leadCapture_firstName" style="width:80px" type="text"></td> 
        <td align="right">Last Name:</td> 
        <td><input name="leadCapture.lastName" value="" id="leadCaptureList_leadCapture_lastName" style="width:80px" type="text"></td> 
        <td align="right">Email:</td> 
        <td><input name="leadCapture.email" value="" id="leadCaptureList_leadCapture_email" style="width:80px" type="text"></td> 


        <td align="right">Phone No.:</td> 
        <td><input name="leadCapture.phone" value="" id="phoneNo" style="width:80px" type="text"></td> 
        <td align="right">Status:</td> 
        <td><select name="leadCapture.status" id="leadCaptureList_leadCapture_status"> 
    <option value="">-- Select Status --</option> 
    <option value="New">New</option> 
    <option value="Converted">Converted</option> 


</select> 

        </td> 

       </tr> 




       <tr id="advancedSearchRow1" style="display: none"> 
         <td align="right">Company:</td> 
        <td><input name="leadCapture.company" value="" id="leadCaptureList_leadCapture_company" style="width:80px" type="text">  </td> 

        <td align="right">Address:</td> 
        <td><input name="leadCapture.address" value="" id="leadCaptureList_leadCapture_address" style="width:128px" type="text"></td> 

        <td align="right">City:</td> 
        <td><input name="leadCapture.city" value="" id="leadCaptureList_leadCapture_city" style="width:122px" type="text"></td> 
         <td align="right">State:</td> 
        <td><select name="leadCapture.state" id="leadCaptureList_leadCapture_state"> 
    <option value="">-- Select State --</option> 
    <option value="AK">Alaska</option> 



</select> 

        </td> 
         <td align="right">Zip Code:</td> 
        <td><input name="leadCapture.zip" value="" id="leadCaptureList_leadCapture_zip" style="width:80px" type="text"></td> 

       </tr> 
       <tr id="advancedSearchRow2" style="display: none"> 
        <td align="right">Lead History:</td> 
        <td><input name="leadCapture.leadHistory" value="" id="leadCaptureList_leadCapture_leadHistory" style="width:80px" type="text"></td> 

        <td align="right">Category:</td> 
        <td><select name="leadCapture.leadCategory.id" id="leadCategorySearch1" style="width:122px"> 
    <option value="0" selected="selected">All Leads</option> 
    <option value="2">Business Leads</option> 
    <option value="200">Webinar Follow up 12/4</option> 


</select> 
</td> 

        <td align="right">Custom Field Type:</td> 
        <td><select name="leadCapture.leadTypeObj.id" id="leadTypeId" style="width:122px" onclick="disableLeadType()" onchange="showCustomFields();"> 
    <option value="0" selected="selected">-Select Type-</option> 
    <option value="16">Contacts</option> 
    <option value="139">ZMS: How can we help you?</option> 
    <option value="178">Gita</option> 
    <option value="206">111 test</option> 


</select> 
</td> 


        <td align="right">Interest :</td> 
        <td><input name="leadCapture.interest" value="" id="leadCaptureList_leadCapture_interest" style="width:80px" type="text"> 
        </td> 
        <td align="right">Score :</td> 
        <td colspan="2"> 
        <select name="scoreLogicalOperator" id="leadCaptureList_scoreLogicalOperator"> 
    <option value="greater" selected="selected">Greater than</option> 
    <option value="less">Less than</option> 
    <option value="equal">Equal to</option> 


</select> 

        &nbsp; 
        <input name="serachByleadScore" value="" id="leadCaptureList_serachByleadScore" style="width:80px" type="text"> 
        </td> 

       </tr> 

       <tr id="advancedSearchRow3" style="display: none"> 
        <td align="right">Lead Source:</td> 
        <td><input name="leadCapture.leadSource" value="" id="leadCaptureList_leadCapture_leadSource" style="width:80px" type="text"></td> 

        <td align="right">Ad Code:</td> 
        <td><input name="leadCapture.adCode" value="" id="leadCaptureList_leadCapture_adCode" style="width:80px" type="text"></td> 

        <td colspan="8" align="right"></td> 

       </tr> 


       <tr> 
        <td colspan="3" align="right" width="250px;"> 

        <img src="images/btn_m_save_search.png" id="saveLeadSearchId" onclick="return popUpForSaveLeadSearch();" align="absmiddle" border="0"> 
         <select name="savedSearchCriteria.id" id="leadCaptureList_savedSearchCriteria_id" onclick="disableLeadSearch()" onchange="return selectSearchCriteriaByName();"> 
    <option value="-1" selected="selected">--Select a search--</option> 


</select> 
</td> 
        <td colspan="6"><input style="display: none;" value="Delete Search" onclick="return deleteLeadSearchData();" id="deleteSearchButton" type="button"></td> 

        <td id="tdForAdvancedSearch" align="right"><a href="javascript:advancedSearch()" id="advancedSearchLink"><img src="images/btn_m_show_advanced.png" border="0"></a> 
        </td> 

        <td colspan="3" align="right"><input alt="true" src="images/btn_search.png" id="leadCaptureList_searchBtn" name="searchBtn" value="true" onclick="$('#pageNumber').val(1);return validSearchField();" type="image"> 

        &nbsp;<input alt="Submit" src="images/btn_m_clear_search.png" id="leadCaptureList_0" value="Submit" onclick="clearAllSearchFields();" type="image"> 
</td> 

       </tr> 


      </tbody></table> 
      </td> 
     </tr> 
    </tbody></table> 
    <div id="customFieldsDiv"></div> 
    <input name="noOfLeadsToBeDisplayed" value="250" id="noOfLeadsToBeDisplayedId" type="hidden"> 
    <input name="pagination" value="" id="pagination" type="hidden"> 
    <input name="pageNumber" value="1" id="pageNumber" type="hidden"> 
    <input name="backButton" value="false" id="backButton" type="hidden"> 
    <input name="nextButton" value="false" id="nextButton" type="hidden"> 
    <input name="saveSearchFlag" value="false" id="leadCaptureList_saveSearchFlag" type="hidden"> 

    </form></div> 

</div></div></td></tr></tbody></table> 
+0

任何幫助,這可能嗎?如果我上面的問題不清楚,請在這裏告訴我 – obama

+0

_Never_將代碼作爲圖像發佈。沒有人能夠重現這樣的事情。如果代碼太大而無法將其置於問題中,請將相關部分放入問題中,並將其他所有內容放在[Gist](https://gist.github.com/)或任何您想要的位置。 –

+1

帶有id屬性的文本框不管它是嵌套還是非嵌套元素都沒有區別。文本框在頁面呈現時可見嗎?或者它是動態的? –

回答

0

發現它有一個id屬性要切實不能不文本框

HTML代碼。硒會在那裏找到它。如果在執行findElement命令時元素在DOM中不存在/可見,則Selenium將拋出異常。

您可以嘗試顯式的webdriver等待這樣,看看它的工作原理:

WebElement textBox = (new WebDriverWait(driver, 10)) 
    .until(ExpectedConditions.visibilityOfElementLocated(By.id("leadCaptureList_leadCapture_firstName"))); 
+0

在生成的html代碼中,我看到這個文本框的id已經加載並且可見。但爲什麼它不選擇。任何建議? – obama