【发布时间】:2018-06-27 17:45:12
【问题描述】:
我正在使用机器人框架和 selenium 库来自动测试网站。
我需要点击某个框架下的元素的菜单,测试如下:
# 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
…
执行 click menu2b 时,selenium 引发异常: 找不到带有定位器“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
我还将 selenium 速度设置为 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不同...
【问题讨论】: