Selenium Robot框架-无法定位创建的元素
我试图将文本输入到React创建的元素中。到目前为止,我已经尝试了以下方法:Selenium Robot框架-无法定位创建的元素,selenium,xpath,robotframework,Selenium,Xpath,Robotframework,我试图将文本输入到React创建的元素中。到目前为止,我已经尝试了以下方法: Input Text css:input#textfield-1198-inputEl TEXT Input Text css:input.x-form-field x-form-required-field x-form-#textfield-1198-inputEl TEXT Input Text xpath=//input[contains(@name,'textfield-1
Input Text css:input#textfield-1198-inputEl TEXT
Input Text css:input.x-form-field x-form-required-field x-form-#textfield-1198-inputEl TEXT
Input Text xpath=//input[contains(@name,'textfield-1198-inputEl')] TEXT
Input Text xpath=//*[@id="textfield-1198-inputEl"] TEXT
以及尝试绝对和相对路径,尽管它总是以-响应,但不匹配任何元素。
等待元素可见并超时
任何帮助都将不胜感激
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="x-window x-layer x-window-default x-closable x-window-closable x-window-default-closable x-border-box x-resizable x-window-resizable x-window-default-resizable" id="window-1196" style="width: 316px; height: 195px; right: auto; left: 630px; top: 315px; z-index: 19001;" tabindex="-1">
<div class="x-window-header x-header x-header-horizontal x-header-draggable x-docked x-unselectable x-window-header-default x-horizontal x-window-header-horizontal x-window-header-default-horizontal x-top x-window-header-top x-window-header-default-top x-docked-top x-window-header-docked-top x-window-header-default-docked-top" id="window-1196_header" style="right: auto; left: 0px; top: 0px; width: 316px;">
<div class="x-header-body x-window-header-body x-window-header-body-default x-window-header-body-horizontal x-window-header-body-default-horizontal x-window-header-body-top x-window-header-body-default-top x-window-header-body-docked-top x-window-header-body-default-docked-top x-box-layout-ct x-window-header-body-default-horizontal x-window-header-body-default-top x-window-header-body-default-docked-top" id="window-1196_header-body" style="width: 309px;">
<div class="x-box-inner" id="window-1196_header-innerCt" role="presentation" style="width: 309px; height: 15px;">
<div class="x-box-target" id="window-1196_header-targetEl" style="width: 309px;">
<div class="x-component x-header-text-container x-window-header-text-container x-window-header-text-container-default x-box-item x-component-default" id="window-1196_header_hd" style="right: auto; left: 0px; top: 0px; margin: 0px; width: 288px;">
<span class="x-header-text x-window-header-text x-window-header-text-default" id="window-1196_header_hd-textEl"> </span>
</div>
<div class="x-tool x-box-item x-tool-default x-tool-after-title" id="tool-1203" style="width: 15px; height: 15px; right: auto; left: 294px; top: 0px; margin: 0px;"><img class="x-tool-img x-tool-close" id="tool-1203-toolEl" role="presentation" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="></div>
</div>
</div>
</div>
</div>
<div class="x-window-body x-window-body-default x-closable x-window-body-closable x-window-body-default-closable x-window-body-default x-window-body-default-closable x-resizable x-window-body-resizable x-window-body-default-resizable" id="window-1196-body" style="overflow: auto; left: 0px; width: 316px; height: 165px; top: 30px;">
<span id="window-1196-outerCt" style="display:table;"></span>
<div class="" id="window-1196-innerCt" style="height: 100%; vertical-align: top; display: table-cell;">
<span id="window-1196-outerCt" style="display:table;"></span>
<div class="x-panel x-window-item x-panel-default" id="createCMDBPanel-1197" style="width: 316px; height: 165px;">
<span id="window-1196-outerCt" style="display:table;"></span>
<div class="x-panel-body x-panel-body-default x-panel-body-default x-docked-noborder-top x-docked-noborder-right x-docked-noborder-bottom x-docked-noborder-left" id="createCMDBPanel-1197-body" style="padding: 0px; left: 0px; top: 0px; width: 316px; height: 125px;">
<span id="window-1196-outerCt" style="display:table;"><span id="createCMDBPanel-1197-outerCt" style="display:table;"></span></span>
<div class="" id="createCMDBPanel-1197-innerCt" style="height: 100%; vertical-align: top; padding: 10px; display: table-cell;">
<span id="window-1196-outerCt" style="display:table;"></span>
<table cellpadding="0" class="x-field x-table-plain x-form-item x-form-type-text x-field-default x-anchor-form-item" id="textfield-1198" style="table-layout: auto;">
<tbody>
<tr class="x-form-item-input-row" id="textfield-1198-inputRow" role="presentation">
<td class="x-field-label-cell" id="textfield-1198-labelCell" role="presentation" style="" valign="top" width="105"><label class="x-form-item-label x-unselectable x-form-item-label-left" for="textfield-1198-inputEl" id="textfield-1198-labelEl" style="width:100px;margin-right:5px;">CMDB Name:</label></td>
<td class="x-form-item-body" colspan="2" id="textfield-1198-bodyEl" role="presentation"><input aria-invalid="false" autocomplete="off" class="x-form-field x-form-required-field x-form-text" data-errorqtip="" id="textfield-1198-inputEl" name="textfield-1198-inputEl" type="text" value="new CMDB"></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
CMDB名称:
一般来说,属性值是“半动态的”(我的术语,不要在上面引用我的话:)-它们是由框架根据需要生成的,并且可以在源代码轻微更改时更改。这适用于类
以及id
属性-正如您可以看到的,其中的数字1198没有语义意义,它只是一个计数器。因此,最好不要在定位器中使用它们,因为它们不会僵硬-值可以在构建之间轻松更改,而不会发出警告 我会用不同的策略来处理它;下面是一个有效的xpath定位器,其结构分解如下:
//td[label[text()="CMDB Name:"]]/following-sibling::td/input[@type="text"]
它首先选择一个表单元格,该单元格的子元素span
包含该文本-用户在UI中看到的输入标签。然后它选择下一个单元格(后面的同级轴),最后选择作为其子元素的输入元素
实际上,此定位器的内容是:“返回文本‘CMDB名称:’旁边的输入”这是实际的错误消息吗?尽可能精确。嗨,@Todor!因此,使用当前的React方法,由于classed、ids和DOM遍历,我们拥有的所有优势都是。。。跑了?我们又开始分析文本了?这是一个非常坏的消息:(我不会说它有那么坏;ID是可以修复的,加上开发总是可以设置一个自定义元素属性,该属性具有预定义的值,用于定位器。类-它们是禁止使用的(但情况一直如此,至少对于==比较而言).Handy提示:安装Selenium IDE并记录操作。打开项目文件后,可以输入文本xpath=//span/div/table/tbody/tr/td[2]/Input…project options=“targets”:[[[“id=textfield-1198-inputEl”,“id”],[“name=textfield-1198-inputEl”,“name”],[“css=#textfield-1198-inputEl”,“css”],[“xpath=//input[@id='textfield-1198-inputEl'],“xpath:attributes”],[“xpath=//td[@id='textfield-1198-bodyEl']/input”,“xpath:idRelative”],[“xpath=///span/div/table/tbody/tr/td[2]/input”,“xpath:position”],