我正在使用机器人框架和硒库自动测试网站。
我需要单击菜单,其中某些元素位于某个框架下,测试如下所示:
# switch to default content first
unselect frame
# switch to level one menu's frame which id is head and click menu1a which id is menu1a
select frame head
click menu1a
# switch to level two menu's frame which id is menuFrame and click menu2a which id is menu2a
unselect frame
select frame menuFrame
click menu2a
# do some testing
…
# then I need to do some other testing in another menu
# switch to default content first
unselect frame
# switch to level one menu's frame which id is head and click menu1b which id is menu1b
select frame head
click menu1b
unselect frame
# switch to level two menu's frame which id is menuFrame and click menu2b which id is menu2b
select frame menuFrame
click menu2b
# do some other testing
…
执行单击menu2b时,硒引发异常: 找不到带有定位符“ menu2b”的元素。
当手动单击menu1a和menu1b时,第二级菜单(menu2a,menu2b)在div内并在同一个框架(名为menuFrame)下动态变化,并且如果我在同一一级菜单下找到不同的第二级菜单,可以,如下所示:
unselect frame
select frame head
click menu1a
unselect frame
select frame menuFrame
click menu2a
# do some testing
…
unselect frame
select frame head
click menu1a
unselect frame
select frame menuFrame
click menu2c
# do some other testing
我还将硒速度设置为1秒,在执行每个命令后将等待1秒钟,但仍然会引发异常。
更新:
当我按F12键找到menu2b元素时,html是:
<li id="22" onclick="showStation(1012);"><a class="innerA" target="mainFrame" href="test.jsp">menu2b</a></li>
但是,当我在执行时打印页面源代码时,html是:
<li id="50" onclick="showStation(1012);"><a class="innerA" target="mainFrame" href="test.jsp">menu2b</a></li>
元素ID不同...
答案 0 :(得分:0)
此问题的原因仍然未知,可能是javascript修改了元素ID。 几个小时后,我找到了一种解决问题的方法,即按文本查找元素,因为元素文本始终不变。