当前位置: 首页 > 知识库问答 >
问题:

双击表格行,在输入字段中插入值

尉迟鑫鹏
2023-03-14

我有一个有角度的表格,其中行选择:

<div class="ag-root-wrapper-body ag-layout-normal ag-focus-managed" ref="rootWrapperBody"><div class="ag-tab-guard ag-tab-guard-top" role="presentation" tabindex="0"></div>
                    <!--AG-GRID-COMP--><div class="ag-root ag-unselectable ag-layout-normal" role="grid" unselectable="on" ref="gridPanel" aria-rowcount="2" aria-colcount="4">
        <!--AG-HEADER-ROOT--><div class="ag-header ag-focus-managed ag-pivot-off" role="presentation" ref="headerRoot" unselectable="on" style="height: 26px; min-height: 26px;">
            <div class="ag-pinned-left-header ag-hidden" ref="ePinnedLeftHeader" role="presentation" style="width: 0px; max-width: 0px; min-width: 0px;"><div class="ag-header-row ag-header-row-column" role="row" aria-rowindex="1" style="top: 0px; height: 25px; width: 0px;"></div></div>
            <div class="ag-header-viewport" ref="eHeaderViewport" role="presentation">
                <div class="ag-header-container" ref="eHeaderContainer" role="rowgroup" style="width: 700px; transform: translateX(0px);"><div class="ag-header-row ag-header-row-column" role="row" aria-rowindex="1" style="top: 0px; height: 25px; width: 700px;"><div class="ag-header-cell ag-focus-managed ag-header-cell-sortable" role="columnheader" unselectable="on" tabindex="-1" aria-sort="none" aria-colindex="1" col-id="operationCodeName" style="width: 300px; left: 0px;">
            <div ref="eResize" class="ag-header-cell-resize ag-hidden" role="presentation"></div>
            <!--AG-CHECKBOX--><div role="presentation" ref="cbSelectAll" class="ag-header-select-all ag-labeled ag-label-align-right ag-checkbox ag-input-field ag-hidden">
                <div ref="eLabel" class="ag-input-field-label ag-label ag-hidden ag-checkbox-label"></div>
                <div ref="eWrapper" class="ag-wrapper ag-input-wrapper ag-checkbox-input-wrapper" role="presentation">
                    <input ref="eInput" class="ag-input-field-input ag-checkbox-input" type="checkbox" id="ag-242-input" tabindex="-1" aria-label="Press Space to toggle all rows selection (unchecked)">
                </div>
            </div>
        <div class="ag-cell-label-container ag-header-cell-sorted-none">
            
            <div ref="eLabel" class="ag-header-cell-label" role="presentation" unselectable="on">
                <span ref="eText" class="ag-header-cell-text" unselectable="on">Operation Code</span>
                <span ref="eFilter" class="ag-header-icon ag-header-label-icon ag-filter-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-filter" unselectable="on" role="presentation"></span></span>
                <span ref="eSortOrder" class="ag-header-icon ag-header-label-icon ag-sort-order ag-hidden" aria-hidden="true"></span>
                <span ref="eSortAsc" class="ag-header-icon ag-header-label-icon ag-sort-ascending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-up"></i></span>
                <span ref="eSortDesc" class="ag-header-icon ag-header-label-icon ag-sort-descending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-down"></i></span>
                <span ref="eSortNone" class="ag-header-icon ag-header-label-icon ag-sort-none-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-none" unselectable="on" role="presentation"></span></span>
            </div>
        </div></div><div class="ag-header-cell ag-focus-managed ag-header-cell-sortable" role="columnheader" unselectable="on" tabindex="-1" aria-sort="none" aria-colindex="2" col-id="accessorialExpectedAmount" style="width: 150px; left: 300px;">
            <div ref="eResize" class="ag-header-cell-resize ag-hidden" role="presentation"></div>
            <!--AG-CHECKBOX--><div role="presentation" ref="cbSelectAll" class="ag-header-select-all ag-labeled ag-label-align-right ag-checkbox ag-input-field ag-hidden">
                <div ref="eLabel" class="ag-input-field-label ag-label ag-hidden ag-checkbox-label"></div>
                <div ref="eWrapper" class="ag-wrapper ag-input-wrapper ag-checkbox-input-wrapper" role="presentation">
                    <input ref="eInput" class="ag-input-field-input ag-checkbox-input" type="checkbox" id="ag-245-input" tabindex="-1" aria-label="Press Space to toggle all rows selection (unchecked)">
                </div>
            </div>
        <div class="ag-cell-label-container ag-header-cell-sorted-none">
            
            <div ref="eLabel" class="ag-header-cell-label" role="presentation" unselectable="on">
                <span ref="eText" class="ag-header-cell-text" unselectable="on">Expected</span>
                <span ref="eFilter" class="ag-header-icon ag-header-label-icon ag-filter-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-filter" unselectable="on" role="presentation"></span></span>
                <span ref="eSortOrder" class="ag-header-icon ag-header-label-icon ag-sort-order ag-hidden" aria-hidden="true"></span>
                <span ref="eSortAsc" class="ag-header-icon ag-header-label-icon ag-sort-ascending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-up"></i></span>
                <span ref="eSortDesc" class="ag-header-icon ag-header-label-icon ag-sort-descending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-down"></i></span>
                <span ref="eSortNone" class="ag-header-icon ag-header-label-icon ag-sort-none-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-none" unselectable="on" role="presentation"></span></span>
            </div>
        </div></div><div class="ag-header-cell ag-focus-managed ag-header-cell-sortable" role="columnheader" unselectable="on" tabindex="-1" aria-sort="none" aria-colindex="3" col-id="accessorialActualAmount" style="width: 150px; left: 450px;">
            <div ref="eResize" class="ag-header-cell-resize ag-hidden" role="presentation"></div>
            <!--AG-CHECKBOX--><div role="presentation" ref="cbSelectAll" class="ag-header-select-all ag-labeled ag-label-align-right ag-checkbox ag-input-field ag-hidden">
                <div ref="eLabel" class="ag-input-field-label ag-label ag-hidden ag-checkbox-label"></div>
                <div ref="eWrapper" class="ag-wrapper ag-input-wrapper ag-checkbox-input-wrapper" role="presentation">
                    <input ref="eInput" class="ag-input-field-input ag-checkbox-input" type="checkbox" id="ag-248-input" tabindex="-1" aria-label="Press Space to toggle all rows selection (unchecked)">
                </div>
            </div>
        <div class="ag-cell-label-container ag-header-cell-sorted-none">
            
            <div ref="eLabel" class="ag-header-cell-label" role="presentation" unselectable="on">
                <span ref="eText" class="ag-header-cell-text" unselectable="on">Actual</span>
                <span ref="eFilter" class="ag-header-icon ag-header-label-icon ag-filter-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-filter" unselectable="on" role="presentation"></span></span>
                <span ref="eSortOrder" class="ag-header-icon ag-header-label-icon ag-sort-order ag-hidden" aria-hidden="true"></span>
                <span ref="eSortAsc" class="ag-header-icon ag-header-label-icon ag-sort-ascending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-up"></i></span>
                <span ref="eSortDesc" class="ag-header-icon ag-header-label-icon ag-sort-descending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-down"></i></span>
                <span ref="eSortNone" class="ag-header-icon ag-header-label-icon ag-sort-none-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-none" unselectable="on" role="presentation"></span></span>
            </div>
        </div></div><div class="ag-header-cell ag-focus-managed ag-header-cell-sortable" role="columnheader" unselectable="on" tabindex="-1" aria-sort="none" aria-colindex="4" col-id="accessorialExpectedUOMShortName" style="width: 100px; left: 600px;">
            <div ref="eResize" class="ag-header-cell-resize ag-hidden" role="presentation"></div>
            <!--AG-CHECKBOX--><div role="presentation" ref="cbSelectAll" class="ag-header-select-all ag-labeled ag-label-align-right ag-checkbox ag-input-field ag-hidden">
                <div ref="eLabel" class="ag-input-field-label ag-label ag-hidden ag-checkbox-label"></div>
                <div ref="eWrapper" class="ag-wrapper ag-input-wrapper ag-checkbox-input-wrapper" role="presentation">
                    <input ref="eInput" class="ag-input-field-input ag-checkbox-input" type="checkbox" id="ag-261-input" tabindex="-1" aria-label="Press Space to toggle all rows selection (unchecked)">
                </div>
            </div>
        <div class="ag-cell-label-container ag-header-cell-sorted-none">
            
            <div ref="eLabel" class="ag-header-cell-label" role="presentation" unselectable="on">
                <span ref="eText" class="ag-header-cell-text" unselectable="on">UOM</span>
                <span ref="eFilter" class="ag-header-icon ag-header-label-icon ag-filter-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-filter" unselectable="on" role="presentation"></span></span>
                <span ref="eSortOrder" class="ag-header-icon ag-header-label-icon ag-sort-order ag-hidden" aria-hidden="true"></span>
                <span ref="eSortAsc" class="ag-header-icon ag-header-label-icon ag-sort-ascending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-up"></i></span>
                <span ref="eSortDesc" class="ag-header-icon ag-header-label-icon ag-sort-descending-icon ag-hidden" aria-hidden="true"><i class="fas fa-arrow-circle-down"></i></span>
                <span ref="eSortNone" class="ag-header-icon ag-header-label-icon ag-sort-none-icon ag-hidden" aria-hidden="true"><span class="ag-icon ag-icon-none" unselectable="on" role="presentation"></span></span>
            </div>
        </div></div></div></div>
            </div>
            <div class="ag-pinned-right-header ag-hidden" ref="ePinnedRightHeader" role="presentation" style="width: 0px; max-width: 0px; min-width: 0px;"><div class="ag-header-row ag-header-row-column" role="row" aria-rowindex="1" style="top: 0px; height: 25px; width: 0px;"></div></div>
        </div>
        <div class="ag-floating-top" ref="eTop" role="presentation" unselectable="on" style="min-height: 0px; height: 0px; display: none; overflow-y: hidden;">
            <div class="ag-pinned-left-floating-top ag-hidden" ref="eLeftTop" role="presentation" unselectable="on"></div>
            <div class="ag-floating-top-viewport" ref="eTopViewport" role="presentation" unselectable="on">
                <div class="ag-floating-top-container" ref="eTopContainer" role="presentation" unselectable="on" style="width: 700px; transform: translateX(0px);"></div>
            </div>
            <div class="ag-pinned-right-floating-top ag-hidden" ref="eRightTop" role="presentation" unselectable="on"></div>
            <div class="ag-floating-top-full-width-container ag-hidden" ref="eTopFullWidthContainer" role="presentation" unselectable="on"></div>
        </div>
        <div class="ag-body-viewport ag-layout-normal ag-row-no-animation" ref="eBodyViewport" role="presentation">
            <div class="ag-pinned-left-cols-container ag-hidden" ref="eLeftContainer" role="presentation" unselectable="on" style="height: 50px;"><div role="row" row-index="0" aria-rowindex="2" row-id="0" comp-id="253" class="ag-row ag-row-even ag-row-level-0 ag-row-position-absolute ag-row-first ag-row-last ag-row-focus ag-row-selected" aria-selected="true" style="height: 50px; transform: translateY(0px); " aria-label="Press SPACE to deselect this row."></div></div>
            <div class="ag-center-cols-clipper" ref="eCenterColsClipper" role="presentation" unselectable="on" style="height: 50px;">
                <div class="ag-center-cols-viewport" ref="eCenterViewport" role="presentation" style="height: calc(100% + 17px);">
                    <div class="ag-center-cols-container" ref="eCenterContainer" role="rowgroup" unselectable="on" style="width: 700px; height: 50px;"><div role="row" row-index="0" aria-rowindex="2" row-id="0" comp-id="253" class="ag-row ag-row-even ag-row-level-0 ag-row-position-absolute ag-row-first ag-row-last ag-row-focus ag-row-selected ag-row-not-inline-editing" aria-selected="true" style="height: 50px; transform: translateY(0px); " aria-label="Press SPACE to deselect this row."><div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="4" comp-id="263" col-id="accessorialExpectedUOMShortName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 100px; left: 600px;  ">m</div><div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="1" comp-id="254" col-id="operationCodeName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 300px; left: 0px;  ">Accessorial Charge</div><div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="2" comp-id="255" col-id="accessorialExpectedAmount" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value ag-cell-focus" style="width: 150px; left: 300px;  ">3.00000000</div><div tabindex="-1" id="ted-test" unselectable="on" role="gridcell" aria-colindex="3" comp-id="256" col-id="accessorialActualAmount" class="ag-cell ag-cell-auto-height ag-cell-value ag-cell-not-inline-editing" style="width: 150px; left: 450px;  ">NaN</div></div></div>
                </div>
            </div>
            <div class="ag-pinned-right-cols-container ag-hidden" ref="eRightContainer" role="presentation" unselectable="on" style="height: 50px;"><div role="row" row-index="0" aria-rowindex="2" row-id="0" comp-id="253" class="ag-row ag-row-even ag-row-level-0 ag-row-position-absolute ag-row-first ag-row-last ag-row-focus ag-row-selected" aria-selected="true" style="height: 50px; transform: translateY(0px); " aria-label="Press SPACE to deselect this row."></div></div>
            <div class="ag-full-width-container" ref="eFullWidthContainer" role="presentation" unselectable="on" style="height: 50px;"></div>
        </div>
        <div class="ag-floating-bottom" ref="eBottom" role="presentation" unselectable="on" style="min-height: 0px; height: 0px; display: none; overflow-y: hidden;">
            <div class="ag-pinned-left-floating-bottom ag-hidden" ref="eLeftBottom" role="presentation" unselectable="on"></div>
            <div class="ag-floating-bottom-viewport" ref="eBottomViewport" role="presentation" unselectable="on">
                <div class="ag-floating-bottom-container" ref="eBottomContainer" role="presentation" unselectable="on" style="width: 700px; transform: translateX(0px);"></div>
            </div>
            <div class="ag-pinned-right-floating-bottom ag-hidden" ref="eRightBottom" role="presentation" unselectable="on"></div>
            <div class="ag-floating-bottom-full-width-container ag-hidden" ref="eBottomFullWidthContainer" role="presentation" unselectable="on"></div>
        </div>
        <div class="ag-body-horizontal-scroll" ref="eHorizontalScrollBody" aria-hidden="true" style="height: 17px; max-height: 17px; min-height: 17px;">
            <div class="ag-horizontal-left-spacer ag-scroller-corner" ref="eHorizontalLeftSpacer" style="width: 0px; max-width: 0px; min-width: 0px;"></div>
            <div class="ag-body-horizontal-scroll-viewport" ref="eBodyHorizontalScrollViewport" style="height: 17px; max-height: 17px; min-height: 17px;">
                <div class="ag-body-horizontal-scroll-container" ref="eBodyHorizontalScrollContainer" style="width: 700px; height: 17px; max-height: 17px; min-height: 17px;"></div>
            </div>
            <div class="ag-horizontal-right-spacer ag-scroller-corner" ref="eHorizontalRightSpacer" style="width: 0px; max-width: 0px; min-width: 0px;"></div>
        </div>
        <!--AG-OVERLAY-WRAPPER--><div class="ag-overlay ag-hidden" aria-hidden="true" ref="overlayWrapper">
            <div class="ag-overlay-panel">
                <div class="ag-overlay-wrapper ag-layout-normal ag-overlay-no-rows-wrapper" ref="eOverlayWrapper"></div>
            </div>
        </div>
    </div>
                    
                <div class="ag-tab-guard ag-tab-guard-bottom" role="presentation" tabindex="0"></div></div>

(请参阅我有nan值的输入字段)

当我双击Nan值时,我得到:

              <div ref="eLabel" class="ag-input-field-label ag-label ag-hidden ag-text-field-label"></div>
             <div ref="eWrapper" class="ag-wrapper ag-input-wrapper ag-text-field-input-wrapper" role="presentation">
                    <input ref="eInput" class="ag-input-field-input ag-text-field-input" type="text" id="ag-285-input" aria-label="Input Editor">
                </div>
            </div></div></div></div></div>

全码:https://pastebin.com/hnvj56pz

我使用这段代码双击表行并将一个值插入输入字段:

    WebElement element = driver.findElement(By.xpath("/......iv[3]"));
            Actions builder = new Actions(driver);
            builder.doubleClick(element).perform();
    
            Thread.sleep(3000);
    
            // Insert into Accessorial Tasks screen Actual value
            insertInputFieldByXPath(driver, "...../input",
                    "3");

protected void insertInputFieldByXPath(WebDriver driver, String input_id, String value){
        WebDriverWait webDriverWait = new WebDriverWait(driver, 15);
        WebElement webElement = webDriverWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(input_id)));
        webElement.clear();  // First we delete the old value in case if this is a spinner
        webElement.sendKeys(value);
    }

当我用Selenium双击时,表格行变成输入字段。但当我尝试输入某个值时,由于id是动态生成的,因此找不到id。

如何获取输入文件的父级和插入值?

你知道如何解决这个问题吗?

共有1个答案

缑高朗
2023-03-14

当dom更新时,您需要再次获取元素,我认为doubleClick()不需要这样做。我将尝试使用两次单击,获得新的输入元素,然后使用send键发送文本。

 类似资料:
  • 问题内容: 例如,运行查询并查看输出后, 我的输出如下 我将如何导出这些数据,使其看起来如下所示? 还是有一种方法可以在SQL中执行此操作以修改记录以包含引号? 因为在导出时,无论如何都会包含逗号,对吗? 问题答案: 如果您感兴趣的列不超过128个字符,则可以使用QUOTENAME函数。小心一点,因为任何超过128个字符的字符都会返回。

  • 我有一个家庭作业要写“先到先得”和“循环模拟”并比较它们。我开始创建一个链表来制作事件列表。我制作了插入和打印列表函数,但无法使其工作。我的朋友告诉我使用双链表,所以我重新创建了链表,并试图使插入函数工作。我修复了大部分问题,但现在找不到插入函数的错误。当我比较是否插入指针数据和当前指针数据时,While循环语句出现分段错误。我已经阅读了我的C语言书,书中的代码与我的代码相似,并且还通过了双链表分

  • 我第一次使用链表,必须创建一个可以在双链表末尾插入节点的函数。到目前为止我 Node类按顺序接受要存储的值、要指向的下一个指针的值和上一个指针的值。每当我试图在这里插入节点时,我都会得到一个错误,说有一个未处理的异常,并且在写入位置0x00000008时有访问冲突。 我不完全确定这里出了什么问题,但我认为这与根据错误消息取消引用空指针有关。我真的很感激有人帮忙解决这个问题。

  • 问题内容: 我的扩展程序具有一个包含项目的上下文菜单。我想要做的是:右键单击html元素(例如,输入或文本区域),然后选择并单击菜单中的某个项目时- 由扩展名定义的某些值将输入到输入中。 目前,我已经意识到。 简单的输入就可以了。 当存在具有自定义事件处理的输入(例如日历或电话输入或货币输入)时,问题就开始了,这些输入以某种方式转换了用户输入。 由于我直接在元素上设置了一个值-省略了处理逻辑,这会

  • 问题内容: 我正在尝试我的React.js的第一部分,并在很早的时候就陷入了困境…我有下面的代码,该代码将搜索表单呈现为。但是,在搜索框中输入内容无济于事。 大概在通过道具并上下移动时会丢失一些东西,这似乎是一个常见问题。但是我很沮丧-我看不到缺少的东西。 (最终,我会使用其他类型的,但是我只是想让这一类正常工作。) 问题答案: 您尚未将道具放在机箱中。它必须在JSX中。 在文档中充分考虑了将 p

  • 问题内容: 我想编写一个函数,为插入的行返回一列的值(在这种情况下为自动递增的主键)。 本质上,我想插入一些新数据,生成一个新的主键,然后获取该键。我可以简单地在表中查找最高的主键,但是有可能其他人也可以运行该函数,并且我可以返回错误的键,对吗? 解决这个问题的最简单方法是什么? 问题答案: 正如评论中指出的那样,来自MySQL文档: 该函数不受竞争条件的影响,因为它在特定于您的连接的MySQL中