请教,rf自动化测试如何定位对话框的确定,取消按钮,xpath获取每次都在变化
选择复选按钮后,弹出的对话框有3层div,确定取消在这一层如下:<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">确定</span>
</button>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">取消</span>
</button>
</div> 1、最简单的就是//span, 但是可能页面存在重复元素
2、往上找到一个元素(某个属性唯一、不动态变化的),定位到此元素后,然后通过父级、子级等,用相对路径或绝对路径,定位到确定,取消 试试这个:driver.find_element_by_xpath("//button").click(),这个是pyhon+selenium。但转换成RF,也是可以是的,定位元素总是变,主要是元素是动态的,很有可能该元素在其它地方也有引用。仅供参考 我也遇到过用xpath定位就是无法定位。。 cq520131517 发表于 2017-4-12 09:21
试试这个:driver.find_element_by_xpath("//button").click(),这个是pyhon+selenium。但转 ...
这个是python的语法吧。怎么转换到rf呢,谢谢了 你用的是robotFramework?如果是,就用xpath=//button试试
cq520131517 发表于 2017-4-12 11:16
你用的是robotFramework?如果是,就用xpath=//button试试
就是用的robotFramework,还是无法定位到啊。 用xpath=//span,我刚才没有注意你是span,而不是button
cq520131517 发表于 2017-4-12 16:06
用xpath=//span,我刚才没有注意你是span,而不是button
这个我试过啊,也不行呢
test | FAIL |
ValueError: Element locator 'XPath=//span' did not match any elements.
我也按照这个文章搞了,还是不行,http://blog.sina.com.cn/s/blog_911313ce0102x6sq.html,
test | FAIL |
ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
@{b} get window handles
log@{b}
select window by handle ${b} <div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front umapDialog-no-close ui-dialog-buttons"
style="display: block; top: 249px; left: 537px; height: auto; width: 350px;" tabindex="-1" role="dialog"
aria-describedby="ui-id-1" aria-labelledby="ui-id-2">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<div id="ui-id-1" class="ui-dialog-content ui-widget-content" style="display: block;
width: auto; min-height: 0px; max-height: none; height: 95.2px;">
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
</div>
我把弹出的对话框全部贴出来
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front umapDialog-no-close ui-dialog-buttons" style="display: block; top: 249px; left: 537px; height: auto; width: 350px;" tabindex="-1" role="dialog" aria-describedby="ui-id-1" aria-labelledby="ui-id-2">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-id-2" class="ui-dialog-title">提示信息</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" type="button" role="button" title="Close">
</div>
<div id="ui-id-1" class="ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 0px; max-height: none; height: 95.2px;">
<span class="glyphicon glyphicon-question-sign" style="float:left; margin:3px 7px 50px 0;"></span>
是否确定删除该记录
</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
</div>
</div>
我把弹出的对话框全部贴出来 没贴全,再贴下
<div class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-front umapDialog-no-close ui-dialog-buttons" style="display: block; top: 249px; left: 537px; height: auto; width: 350px;" tabindex="-1" role="dialog" aria-describedby="ui-id-1" aria-labelledby="ui-id-2">
<div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
<span id="ui-id-2" class="ui-dialog-title">提示信息</span>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-dialog-titlebar-close" type="button" role="button" title="Close">
</div>
<div id="ui-id-1" class="ui-dialog-content ui-widget-content" style="display: block; width: auto; min-height: 0px; max-height: none; height: 95.2px;">
<span class="glyphicon glyphicon-question-sign" style="float:left; margin:3px 7px 50px 0;"></span>
是否确定删除该记录
</div>
<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix">
<div class="ui-dialog-buttonset">
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">确定</span>
</button>
<button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" type="button" role="button">
<span class="ui-button-text">取消</span>
</button>
</div>
</div>
</div> 学习一下
页:
[1]