Selenium- WebDriver识别输入标记

时间:2016-04-15 10:21:21

标签: java selenium-webdriver

我正在尝试识别td值,东西在TD内部我有输入标签,我需要识别该值。我的Td标签如下所示。我需要识别并获得价值4/11/2016。试图添加完整的源代码

    <div id="accountsSectionBottomContainer" class="acctBottom" default-path="/ui/app.php/AccountsBottomPane/21/acct_glance">
<div>
<div class="accountsModPLSQLReturn" data-aria-plsql-root="/ui/mod_plsql.php/aria/csrtools/" data-aria-plsql-url="dashboard_plan.plan_inst_unit_inst_dtls">
<div class="workbook_tabname">Accounts</div>
<script language="JavaScript" type="text/javascript">         self.focus();      </script>
<div id="account-name">
<style type="text/css"> .color-block dl {     background-color: #F8F8FF;     margin: 0;     padding: 1em; } .white-block dl {     font-size: 1.1em;     margin: 0;     padding: 1em; } .static-block dt {     float: left;     font-size: 1.1em;     font-weight: bold;     margin: 0;     padding: 0;     width: 300px; } .static-block dd {     font-size: 1.1em;     margin: 0 0 0 225px;     padding: 0 0 5px 15px; } </style>
<script language="javascript" type="text/javascript"> $('.trgprdval').trigger('change');    var inFulfilmentStartDate_cal = new calendar3(document.main.inFulfillmentDate, "MM/DD/YYYY");    inFulfilmentStartDate_cal.year_scroll = true;    inFulfilmentStartDate_cal.time_comp = false; function myCdidFunction() {     var newCDID = document.getElementById('inClientDefinedIdentifier').value;     document.getElementById('inNewCdid').value = newCDID;      } function copyRadioVal(inputValue, origVal, inputName, name) {        var hiddenValues = document.getElementsByClassName(name);     console.log(inputName);     console.log(name);     console.log(document.getElementById(inputName));     x = document.getElementById(inputName).checked;     if (x==true)     {         $("#"+origVal).val(inputValue);     } } function copyCheckboxVal(inputValue, origVal, inputName, inPrimacyNo, inputId) {        var x = document.getElementById(inputName).checked;       if (x==true)     {         document.getElementById(origVal).value = inputValue;     }     if (x==false)     {         document.getElementById(origVal).value = "";     }     var inputType = inPrimacyNo.concat(inputId);     document.getElementById(inputType).value = inPrimacyNo; } function joinSelectVal(newInputName, oldInputId) {     var selectval = document.forms["main"][oldInputId];    var selectedList = [];    for (var i = 0; i < selectval.length; i++) {       if (selectval[i].selected) {          selectedList.push(selectval[i].value);       }    }    var checkedStr = Array.join(selectedList, "~");    if (checkedStr.length == 0) {    checkedStr = "NO@VALUE";    }    document.getElementById(newInputName).value = checkedStr; } function validateInputsAndSubmit(button) { var valSuppFields = validateAcctSuppFields('.accountsForm'); if(!valSuppFields['isValid']) { alert(valSuppFields['errorMsg']); return false; } lockAndSubmitForm(button); } </script>
<div class="color-block">
<div class="white-block">
<form class="accountsForm" name="main" method="post" action="/ui/mod_plsql.php/aria/csrtools/dashboard_plan_m.plan_unit_instance_save_m" onsubmit="return false;">
<font size="3">
<br/>
<br/>
<table class="data-table clear-both" cellspacing="0">
<colgroup>
<tbody>
<tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089723</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089723" name="INSERVICES[0][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[0][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[0][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089723" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[0][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089726</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089726" name="INSERVICES[1][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[1][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[1][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089726" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[1][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089727</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089727" name="INSERVICES[2][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[2][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[2][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089727" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[2][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089730</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089730" name="INSERVICES[3][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[3][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[3][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089730" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[3][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089747</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089747" name="INSERVICES[4][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[4][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[4][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089747" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[4][inFulfillmentDate]"/>
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
<font size="3">
<br/>
<br/>
<table class="simple" cellspacing="0">
<input type="hidden" value="8179" name="inPlanNo"/>
<input type="hidden" value="4066308" name="inPlanUnitInstanceNo"/>
<input id="inNewCdid" type="hidden" name="inClientDefinedIdentifier"/>
<input type="hidden" value="MasterPlan" name="inSelectedPlan"/>
<input type="hidden" value="19328197" name="inPlanInstanceNo"/>
<div class="form-buttons">
<input type="hidden" value="AAAAAAUJTTz9lWKS_TgqUANHCenOnmxH2IQHclhl2zoruTE55z7CFHIdaAAJNyGlNLLnb5f-97HVxpFchLgkkTjIFz9d_I_sKfI7EQd83gmsfyFtQA==" name="as_sfid"/>
<input type="hidden" value="yli8W38Xf7v_849HentO" name="as_fid"/>
</form>
</div>
</div>
</div>
    <input id="inFulfillmentDate10089723" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[0][inFulfillmentDate]"/>

</td>

1 个答案:

答案 0 :(得分:0)

嗨,如果你想识别价值=&#34; 4/11/2016&#34;你可以直接使用

如果动态id plz使用

background: linear-gradient(rgba(3, 34, 47, 0.8)

现在在控制台中打印字符串

UPADTE

MyDynamicID = "//*[starts-with(@id,'inFulfillmentDate')]"
String value = driver.findElement(By.id(MyDynamicID )).getText();

Belwo是控制台输出

// our id = inFulfillmentDate  pattern 
    List<WebElement> myDate =  driver.findElements(By.xpath("//*[starts-with(@id,'inFulfillmentDate')]"));
    System.out.println(myDate.size());
    // now print all value 

    for(int i=0;i<myDate.size();i++){
        System.out.println("value is : " +myDate.get(i).getAttribute("value"));
    }