【发布时间】:2020-01-08 14:45:09
【问题描述】:
我已经使用 Robot Framework 几天来在我的工作网络应用程序中自动执行一些基本流程测试并发现了一个问题:
无法使用 id 定位器找到一些 Web 元素
为此,我一直在使用 SeleniumLibrary。尝试使用不同的定位器,例如 xPath 和 CSS 选择器,在查找元素和关键字 Wait Until Page Contains Element 和 Wait Until Element Is Visible 之前设置隐式等待,但仍然给出相同的结果。
首先我检查某个元素是否存在:
Page Should Contain Element id=some-button
然后我尝试将一些键发送到输入:
Input Text id=some-input Some characters
然后我收到错误Element with locator 'id=some-button' not found
页面结构如下:
...
<body>
<div>
...
<div>
<form>
<div>
<button id=some-button />
</div>
<div>
<!--- 8 opening div tags -->
<input id=some-input />
<!--- 8 closing div tags -->
</div>
</form>
</div>
</div>
</body>
...
有人知道为什么会这样吗?
更新:
试过了
/html/body/div/div[1]/form/div[2]/div[1]/div[2]/div[2]/div[2]/div/div[1]/div[1]/div/input
而不是
//*[@id="some-button"]
而且效果很好。
【问题讨论】:
-
您是否尝试在输入之前检查该元素是否存在?
-
运行关键字
Wait Until Element Is Visible和Wait Until Page Contains Element也失败 -
您是否检查过它们是否在 IFRAME 内?
-
文档中没有 iframe 元素。
-
请显示实际的错误信息。
标签: selenium robotframework ui-automation