0

im working with the following HTML

<tbody>
<tr class="formRow">
    <td class="labelColumn">
        <span id="ctl00_MainContent_lblTemplate">Template</span>
    </td>
    <td class="fieldColumn">
        <div id="ctl00_MainContent_ddlTemplate" class="RadDropDownList RadDropDownList_Default" style="width:300px;" tabindex="0">
        <span class="rddlInner"><span class="rddlFakeInput">&lt;No Template&gt;</span><span class="rddlIcon"><!-- &nbsp; --></span></span><div class="rddlSlide" id="ctl00_MainContent_ddlTemplate_DropDown" style="display:none;">
        <div class="rddlPopup rddlPopup_Default">
        <ul class="rddlList">
        <li class="rddlItem  rddlItemSelected">&lt;No Template&gt;</li>
        </ul>
        </div>
        </div><input id="ctl00_MainContent_ddlTemplate_ClientState" name="ctl00_MainContent_ddlTemplate_ClientState" type="hidden" autocomplete="off">
        </div>
         <input name="ctl00$MainContent$Button8" type="button" id="ctl00_MainContent_Button8" class="invisible" style="width: 0px; height: 19px" value="Button">

    </td>
</tr>
<tr id="ctl00_MainContent_trCode" class="formRow">
    <td style="height: 3px" class="labelColumn">
        <span id="ctl00_MainContent_lblCode">Code</span>
    </td>
    <td style="height: 3px" class="fieldColumn">
        <input name="ctl00$MainContent$txtCode" type="text" maxlength="10" id="ctl00_MainContent_txtCode" onkeypress="return UpperCaseFieldKeyPress(this,event);" style="width:110px;">&nbsp;
    </td>
</tr>
<tr class="formRow">
    <td style="height: 20px" class="labelColumn">
        <span id="ctl00_MainContent_lblName" class=" compulsory">Name</span>
    </td>
    <td style="height: 20px" class="fieldColumn">
        <input name="ctl00$MainContent$txtName" type="text" maxlength="40" id="ctl00_MainContent_txtName" style="width:350px;">
    </td>
</tr>
<tr id="ctl00_MainContent_trDescription" class="formRow">
    <td class="labelColumn">
        <span id="ctl00_MainContent_lblDescription">Description</span>&nbsp;
    </td>
    <td class="fieldColumn">
        <textarea name="ctl00$MainContent$txtDescription" rows="2" cols="20" id="ctl00_MainContent_txtDescription" onkeypress="return CheckFieldLengthKeyPress(this, event, 80);" style="height:48px;width:350px;"></textarea>
    </td>
</tr>
<tr id="ctl00_MainContent_trCustomer" class="formRow">
    <td class="labelColumn">
        <span id="ctl00_MainContent_lblCustomer">Customer</span>
    </td>
    <td class="fieldColumn">
        <span class="RadAjaxPanel" id="ctl00_ctl00_MainContent_aeCustomerPanelPanel"><div id="ctl00_MainContent_aeCustomerPanel">

        <span class="RadAjaxPanel" id="ctl00_ctl00_MainContent_txtCustomerCodePanel"><input name="ctl00$MainContent$txtCustomerCode" type="text" maxlength="10" onchange="javascript:setTimeout('__doPostBack(\'ctl00$MainContent$txtCustomerCode\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="ctl00_MainContent_txtCustomerCode" style="width:128px;"></span>
        <span id="ctl00_MainContent_btnFindCustomer_Wrapper" class="LookupImageButtonWrapper">
        <input type="image" name="ctl00$MainContent$btnFindCustomer" id="ctl00_MainContent_btnFindCustomer" class="LookupImageButton" src="../Icons/GetIcon.aspx?n=clearpixel&amp;s=1" onclick="javascript:FindCustomer(''); return false;" style="border-width:0px;">&nbsp;
        </span>
        <span id="ctl00_MainContent_btnAddMultiCustomers_Wrapper" class="MultipleButtonWrapper">
        <input type="image" name="ctl00$MainContent$btnMultiCustomers" id="ctl00_MainContent_btnMultiCustomers" title="Multiple customers" class="AbsMiddle" src="../Icons/16x16/addline.gif" onclick="javascript:EditCustomers(23);return false;" style="border-width:0px;">&nbsp;
        </span>
        <span style="overflow: hidden">
        <span id="ctl00_MainContent_lblCustomerName" class="labelText"></span>
        </span>

        </div><span class="RadAjaxPanel" id="ctl00_ctl00_MainContent_txtCustomerCodePanel"></span></span>

    </td>
</tr>

Im specifically trying to locate the following elements with the ultimate goal of inputting text using sendkeys,

<td style="height: 20px" class="fieldColumn">
   <input name="ctl00$MainContent$txtName" type="text" maxlength="40" id="ctl00_MainContent_txtName" style="width:350px;">
</td>

and

 <td style="height: 3px" class="fieldColumn">
   <input name="ctl00$MainContent$txtCode" type="text" maxlength="10" id="ctl00_MainContent_txtCode" onkeypress="return UpperCaseFieldKeyPress(this,event);" style="width:110px;">&nbsp;
 </td>

so far I have tried the following approaches but have been unable to locate either of them,

driver.FindElement(By.Id("ctl00_MainContent_txtCode"));

throwing: Message: "no such element: Unable to locate element:

driver.FindElement(By.Name("ctl00$MainContent$txtCode"));

throwing: Message: "no such element: Unable to locate element:

driver.FindElements(By.ClassName("fieldColumn"));

I realise this would not find the element I need but thought if I find by class name i could insert a contains clause - this also throws: throwing: Message: "no such element: Unable to locate element:

I can find TagName("tr") & TagName("td") but when I attempt to create a list of all rows using the Id of the table i also get

Message: "no such element: Unable to locate element:

I have found some joy identifying the TagName("tbody") however the same table has multiple "tbody" tags - for this I am using

driver.FindElement((By.TagName("tbody")));

but this always gives me the first tbody which is not the one i want, any help with this would be greatly appreciated?

  • 1
    please check iframe present – Vel Guru Apr 17 '18 at 11:20
1

You may try to use css selector;

 WebElement element = driver.findElement(By.cssSelector("input[name=\"ctl00$MainContent$txtName\"]"));
1

The elements were indeed in an iframe, managed to access the iframe using,

driver.switchTo().frame(0)

Following this I could locate the elements I needed no problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.