【发布时间】:2013-07-11 19:58:42
【问题描述】:
我创建了另一个问题,我认为这是导致此错误的原因:Why does the Selenium Firefox Driver consider my modal not displayed when the parent has overflow:hidden?
Selenium 版本 2.33.0
火狐驱动
导致错误的代码:
System.Threading.Thread.Sleep(5000);
var dimentions = driver.Manage().Window.Size;
var field = driver.FindElement(By.Id("addEmployees-password")); //displayed is true
field.Click(); //works fine
var element = driver.FindElement(By.Id(buttonName)); //displayed is false
element.Click(); //errors out
它试图点击的按钮:
<div id="addEmployees" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="addEmployeesLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3>Add Employee</h3>
</div>
<div class="modal-body">
<p class="alert alert-info">
<input name="addEmployees-username" id="addEmployees-username" />
<input name="addEmployees-password" id="addEmployees-password" type="password" />
<input name="addEmployees-employee" id="addEmployees-employee" />
</p>
</div>
<div class="modal-footer">
<button name="addEmployees-add" id="addEmployees-add" type="button" class="btn" data-ng-click="submit()">Add</button>
</div>
</div>
- 如果我将调用更改为
FindElements,那么我会得到一个元素,因此页面上没有其他任何内容。 - 如果我
FindElement出现在按钮之前的字段上,比如addEmployees-employee,那么addEmployees-employee就是displayed - 在浏览器本身中,它显示得很好,我需要做的就是实际单击按钮并执行所需的行为,但是 webdriver 拒绝考虑显示的元素
如何认为一个字段显示而另一个字段不显示?
右下角有添加按钮的modal,其他元素全部显示=true
每个driver.Manage().Window.Size;的窗口大小为1200x645
元素位置是:800x355y 每 driver.FindElement(By.Id(buttonName)).Location
元素尺寸为:51x30 每 driver.FindElement(By.Id(buttonName)).Size
密码元素位置为:552x233y per driver.FindElement(By.Id("addEmployees-password")).Size
【问题讨论】:
-
我们使用类似的东西:
waitUntil(Waits.elementDisplayed(web element goes here));here at work。您的自动化框架中有类似的机制吗? -
@Brian c#驱动程序有隐式等待,我已经配置了10秒,问题是,在它之前出现的元素被标记为显示,但按钮不是,踢球者是另一个相同但编辑而不是添加的模态可以正常工作!
-
当您查看
DOM时,这两个元素是否始终可见? -
嗯.. 我不确定你的意思是什么,但它们在浏览器视口上是可见的,如果我进入 firebug,它不会被标记为隐藏。这能回答你的问题吗?
-
@ton.yeung:你能调试一下位置和大小吗?也许还有浏览器视口大小。是不是靠近窗户的边缘?
标签: c# angularjs selenium-webdriver angular-strap