C# 如果元素位于页面的用户控件中,如何访问该元素并输入键?

C# 如果元素位于页面的用户控件中,如何访问该元素并输入键?,c#,visual-studio,selenium,user-controls,selenium-chromedriver,C#,Visual Studio,Selenium,User Controls,Selenium Chromedriver,我在一个页面中有一个用户控件UserInfo。用户控件中有一个名为cbType的组合框。如果我正在使用selenium,如何访问此组合框来测试它?我无法使用ID获取元素。FindElement返回空/超时错误 下面是我的代码: [TestMethod] public void Test_GoToAddDepositPage() { IWebElement el = driver.FindElement(By.Id("ctl00_MainContent_ucDepositMasterIn

我在一个页面中有一个用户控件
UserInfo
。用户控件中有一个名为
cbType
的组合框。如果我正在使用selenium,如何访问此组合框来测试它?我无法使用ID获取元素。
FindElement
返回空/超时错误

下面是我的代码:

[TestMethod]
public void Test_GoToAddDepositPage()
{
     IWebElement el = driver.FindElement(By.Id("ctl00_MainContent_ucDepositMasterInput_rcbAccountNo_Input"));
     el.SendKeys("Big"")  
}
这是我正在运行测试的页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="TenantDepositMasterInput.aspx.cs" Inherits="UnionEnergy.Web.DepositModule.TenantDepositMasterInput" %>

<%@ Register Src="~/Control/DepositModule/ucDepositMasterInput.ascx" TagPrefix="uc1" TagName="ucDepositMasterInput" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <link href="../Content/style/management.css" rel="stylesheet" />
    <link href="../Content/style/inputform.css" rel="stylesheet" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <telerik:RadCodeBlock ID="codeBlock1" runat="server">
        <script type="text/javascript">

            function closeWindow() {
                window.close();
            }

        </script>

        <style>

            .input {
                min-width: 250px;
                padding-right: 20px;
            }

        </style>
    </telerik:RadCodeBlock>

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <%--<ClientEvents OnRequestStart="requestStart" OnResponseEnd="responseEnd" />--%>
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="ucDepositMasterInput">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="ucDepositMasterInput" />
                    <telerik:AjaxUpdatedControl ControlID="lblMessage" UpdatePanelCssClass="errMsg" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
    </telerik:RadAjaxLoadingPanel>

    <div id="mainDiv" class="custMgmntMainDiv">

        <h2>Add Deposit Request</h2>

        <asp:Label ID="lblMessage" runat="server"></asp:Label>

        <div class="fullWidthCell" style="background-color: beige;">
            <div class="cellHorizontal">
                <uc1:ucDepositMasterInput runat="server" ID="ucDepositMasterInput" ValidationGroup="Validation" />
            </div>
            <div class="cellHorizontal">

            </div>
        </div>

        <div class="fullWidthCell boxSizing" style="background-color: rgb(255,255,225); padding: 10px 30px;">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="Validation"
                HeaderText='Please correct the following error before proceed:'
                ForeColor="Red" />
        </div>

        <div class="fullWidthCell boxSizing" style="height:22%; background-color: #dddddd; padding: 10px 30px; padding-bottom: 50px;">
            <div class="cellHorizontal">
                <div class="cell">
                    <telerik:RadButton ID="rbSave" runat="server" Width="120px" Text="Save" 
                        OnClick="rbSave_Click" 
                        SingleClick="true" SingleClickText="Submitting..." 
                        ValidationGroup="Validation"></telerik:RadButton>
                </div>
                <div class="cell">
                    <telerik:RadButton ID="rbClose" runat="server" Width="120px" Text="Close" OnClientClicked="closeWindow"></telerik:RadButton>
                </div>
            </div>
        </div>

    </div>
</asp:Content>

函数closeWindow(){
window.close();
}
.输入{
最小宽度:250px;
右边填充:20px;
}
添加存款请求
用户控件:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ucDepositMasterInput.ascx.cs" Inherits="UnionEnergy.Web.Control.DepositModule.ucDepositMasterInput" %>

<div style="padding: 5px 5px 5px 5px;">

    <div class="fullWidthCell">
        <div class="cellHorizontal">
            <div class="cell label">Customer Name</div>
            <div class="cell separator">:</div>
            <div class="cell input">
                <asp:Label ID="lbCustomerName" runat="server"></asp:Label>
            </div>
        </div>
    </div>

    <div class="fullWidthCell">
        <div class="cellHorizontal">
            <div class="cell label">Contract Set ID</div>
            <div class="cell separator">:</div>
            <div class="cell input">
                <telerik:RadComboBox ID="rcbAccountNo" runat="server" Height="200px" AutoPostBack="true" 
                    EmptyMessage="Select Account"
                    EnableLoadOnDemand="true" 
                    ShowMoreResultsBox="true" ItemsPerRequest="20"
                    EnableVirtualScrolling="true"
                    OnItemsRequested="rcbAccountNo_ItemsRequested" 
                    OnSelectedIndexChanged="rcbAccountNo_SelectedIndexChanged"
                    DropDownAutoWidth="Enabled"></telerik:RadComboBox>
                <asp:RequiredFieldValidator ID="rfvAccountNo" runat="server" 
                    Text="*"
                    ErrorMessage="Account No required. "
                    ControlToValidate="rcbAccountNo" InitialValue=""
                    ForeColor="red"
                    Display="Dynamic"></asp:RequiredFieldValidator>
            </div>
        </div>
        <div class="cellHorizontal">
            <div class="cell label"></div>
            <div class="cell separator"></div>
            <div class="cell input">
            </div>
        </div>
    </div>

    <div class="fullWidthCell">
        <div class="cellHorizontal">
            <div class="cell label">Deposit Type</div>
            <div class="cell separator">:</div>
            <div class="cell input">
                <telerik:RadComboBox ID="rcbDepositType" runat="server" AutoPostBack="true" 
                    OnSelectedIndexChanged="rcbDepositType_SelectedIndexChanged" 
                    DropDownAutoWidth="Enabled"></telerik:RadComboBox>
                <asp:RequiredFieldValidator ID="rfvDepositType" runat="server" 
                    Text="*"
                    ErrorMessage="Deposit Type required. "
                    ControlToValidate="rcbDepositType" InitialValue="NIL"
                    ForeColor="red"
                    Display="Dynamic"></asp:RequiredFieldValidator>
            </div>
        </div>
        <div class="cellHorizontal">
            <div class="cell label"></div>
            <div class="cell separator"></div>
            <div class="cell input">
            </div>
        </div>
    </div>

    <div class="fullWidthCell">
        <div class="cellHorizontal">
            <div class="cell label">Requested Amount</div>
            <div class="cell separator">:</div>
            <div class="cell input">
                <telerik:RadNumericTextBox ID="rntbRequested" runat="server">
                    <NegativeStyle Resize="None"></NegativeStyle>
                    <NumberFormat ZeroPattern="n" AllowRounding="False" DecimalDigits="2" GroupSeparator=""></NumberFormat>
                    <EmptyMessageStyle Resize="None"></EmptyMessageStyle>
                    <ReadOnlyStyle Resize="None"></ReadOnlyStyle>
                    <FocusedStyle Resize="None"></FocusedStyle>
                    <DisabledStyle Resize="None"></DisabledStyle>
                    <InvalidStyle Resize="None"></InvalidStyle>
                    <HoveredStyle Resize="None"></HoveredStyle>
                    <EnabledStyle Resize="None"></EnabledStyle>
                </telerik:RadNumericTextBox>
                <asp:RequiredFieldValidator ID="rfvRequested" runat="server"
                    Text="*"
                    ErrorMessage="Requested Amount required. "
                    ControlToValidate="rntbRequested"
                    ForeColor="red"
                    Display="Dynamic"></asp:RequiredFieldValidator>
            </div>
        </div>
        <div class="cellHorizontal">
            <div class="cell label">Payment Status</div>
            <div class="cell separator">:</div>
            <div class="cell input">
                <telerik:RadComboBox ID="rcbPaymentStatus" runat="server" Enabled="false" 
                    DropDownAutoWidth="Enabled"></telerik:RadComboBox>
            </div>
        </div>
    </div>                          
</div>

客户名称
:
合同集ID
:
矿床类型
:
请求的金额
:
支付状态
:

我猜您想使用selenium公开的
SendKeys
函数

它有两种口味

这可能是您需要的:

public Actions SendKeys(
    IWebElement element,
    string keysToSend
)
这将直接发送到浏览器:

public Actions SendKeys(
    string keysToSend
)

我猜您希望使用selenium公开的
SendKeys
函数

它有两种口味

这可能是您需要的:

public Actions SendKeys(
    IWebElement element,
    string keysToSend
)
这将直接发送到浏览器:

public Actions SendKeys(
    string keysToSend
)

你的代码有什么问题?我无法获取用户控件中的元素用相关的HTMLHave更新问题。我已经用代码更新了。已尝试仅使用“rcbAccountNo”按Id搜索,但仍无法检索元素。您的代码有什么问题?我无法在用户控件中获取元素使用相关HTMLHave更新问题已使用代码更新。已尝试仅使用“rcbAccountNo”按Id搜索,但仍无法检索元素。