如何使用Robot Framework处理动态元素 [英] How to handle dynamic elements using Robot Framework

查看:792
本文介绍了如何使用Robot Framework处理动态元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究Robot Framework并使用Selenium2Libraries来处理Web应用程序。我正在处理一个Form,我正在处理一个动态元素,这是一个可编辑的文本区域和下拉列表..



我真的希望有人能够指导我如何做到这一点。我正在做的一个例子是,



[示例元素代码]





< pre class =lang-html prettyprint-override> input id =textfield-1237-inputElclass =x-form-field x-form-text x-form-text-default x- form-focus x-field-form-focus x-field-default-form-focus
data-ref =inputElsize =1name =textfield-1237-inputEl
maxlength =200role =textboxaria-hidden =falsearia-disabled =false
aria-readonly =falsearia-invalid =falsearia-required =falseautocomplete = offdata-componentid =textfield-1237type =text

关于此的任何信息非常感谢。谢谢!

解决方案

当尝试处理动态ID,以及没有简单UID的元素时,最好的方法是四处走动这是使用 Xpath



Xpath基本上是HTML中元素的位置。这是解决没有ID随时可用的问题的最佳方式(我的工作在任何地方都没有我可以使用的ID,因此我别无选择,只能使用Xpath)



如果使用正确,Xpath真的很强大。如果不是它们真的很脆弱,可能是一个难以维持的噩梦。我给你一个你可能必须使用的潜在Xpath的例子:

 从列表中选择xpath =(// select) [2] DropDownItem1 

你说你有一个下拉列表。这是你会看到的潜在看起来像。这里的Xpath基本上是说,在整个HTML页面的任何地方找到你找到的第二个下拉列表。



Xpaths需要一段时间才能完成,特别是如果你有使用ID的luxurary。我用来定位和调试Xpath的工具是:



FireBug



Selenium IDE



我现在主要使用Selenium IDE,因为它是一个很好的工具,基本上可以让你选择一个元素HTML,它会喷出它的ID,CSS路径,Xpath,DOM等等......不仅如此,当您发现更复杂的X路径时,还有一个查找工具可以直观地显示您的X路径指向(或不是,如果错了)



真正帮助我的是这个。这真的很有用,并且有许多例子供你反对。



如果你有任何问题,只需回复并生病帮助



更多示例:

 点击元素// span [包含(text(),'提交')] 
输入文本xpath =(// textarea)[3]一些随机文本!


I am currently working on the Robot Framework and using Selenium2Libraries to work on a Web Application. I'm working on a Form and I'm dealing with a dynamic elements which is an editable text area and drop down list..

I really hope someone would be able to guide me on how I can do this. An example of what I am doing is,

[Example element code]

input id="textfield-1237-inputEl" class="x-form-field x-form-text x-form-text-default x-form-focus x-field-form-focus x-field-default-form-focus" 
data-ref="inputEl" size="1" name="textfield-1237-inputEl" 
maxlength="200" role="textbox" aria-hidden="false" aria-disabled="false" 
aria-readonly="false" aria-invalid="false" aria-required="false" autocomplete="off" data-componentid="textfield-1237" type="text"

Any information on this would be much appreciated. Thanks!

解决方案

When trying to handle dynamic IDs, and elements which dont have easy UIDs about them, the best way to go around this is using Xpath.

Xpaths are basically the location of the element within the HTML. This is kind of the best way to get around the problem of not having ID readily available (My work has no IDs anywhere I can use, thus I have no choice but to use Xpaths)

Xpaths are really powerful, if used correctly. If not they are really brittle and can be a nightmare to maintain. Ill give you an example of potential Xpaths you may have to use:

Select From List By Label    xpath=(//select)[2]    DropDownItem1

You said that you have a drop down. Here is a potenital "look-a-like" you would see. The Xpath here is basically saying, find the 2nd drop down you find, anywhere on the entire HTML page.

Xpaths will take a while to get your head round, esspecially if you have had the luxurary of using IDs. The tools I use in order to locate and debug Xpaths are:

FireBug

Selenium IDE

I mainly use Selenium IDE now, as it is a nice tool which basically lets you "Select" an element within the HTML and it will spurt out its ID, CSS Path, Xpath, DOM, etc... Not only that, when you come to discover more complex Xpaths, there is a "Find" tools which shows you visually, where your Xpath is pointing to (or isnt, if its wrong)

Something which really helped me was This. It is really usful and has a lot of examples for you to work against.

If you have any problems, just reply and ill try to help

More Examples:

Click Element    //span[contains(text(), 'Submit')]
Input Text    xpath=(//textarea)[3]    Some Random Text!

这篇关于如何使用Robot Framework处理动态元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆