我在网站上自动执行测试过程时遇到问题。我有一个项目列表,并且-要添加一个新项目-模态打开。到那时一切都很好-RobotFramework会在复选框和输入中填写文本,但是当涉及到“保存”按钮时,Chrome和Firefox的响应会有所不同。
Chrome会做所有正确的事情,关闭模式并保存新项目。另一方面,Firefox也似乎也单击了按钮,但是什么也没发生。按钮“后面”的代码如下:
<button id="submitSomething" type="submit" name="someName"
value="Save" onclick="window.wishlist.editPreSubmit(this, event)">Save</button>
我尝试过类似的事情:
Execute Javascript document.querySelector("#submitNew").click()
代替
Click Button id=submitSomething
,但可悲的是在Firefox上没有进行任何更改。每个微小的帮助将不胜感激:)
编辑: 如果我使用
document.querySelector("#submitNew").click()
在从robotframework打开的浏览器的控制台中,它也不起作用(firefox),并且我收到警告:
在Windows-1252编解码器中发布的表格,应更改为utf-8
Br
答案 0 :(得分:-1)
要单击所需元素,您需要诱使 WebDriverWait 使元素可点击,并且可以使用以下任一解决方案:
Wait Until Element Is Visible
:
Wait Until Element Is Visible xpath=//button[@id='submitSomething' and @value='Save'][contains(., 'Save')] 20 seconds
Set Focus To Element xpath=//button[@id='submitSomething' and @value='Save'][contains(., 'Save')]
# invoke click
Wait Until Element Is Enabled
:
Wait Until Element Is Enabled xpath=//button[@id='submitSomething' and @value='Save'][contains(., 'Save')] 20 seconds
Set Focus To Element xpath=//button[@id='submitSomething' and @value='Save'][contains(., 'Save')]
# invoke click