我創造了另一個問題,我認爲這是此錯誤的原因:Why does the Selenium Firefox Driver consider my modal not displayed when the parent has overflow:hidden?「元素當前不可見,因此可能不會與」互動「,但另一個是?
硒版本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拒絕考慮顯示的元素
它是如何可以考慮顯示一個字段而不是另一個字段?
在右下角的添加按鈕模態,所有其他元素被顯示=真
窗口尺寸每driver.Manage().Window.Size;
1200x645的元件的位置是:每driver.FindElement(By.Id(buttonName)).Location
800x355y 元素尺寸爲:51x30每driver.FindElement(By.Id(buttonName)).Size
密碼元素的位置是:552x233y每driver.FindElement(By.Id("addEmployees-password")).Size
我們用類似於這樣:'最好推遲(Waits.elementDisplayed(網絡元素放在這裏));'在這裏工作。你的自動化框架中是否有這樣的機制? – Brian
@布賴恩的C#驅動程序隱式等待,我已經配置了10秒,事情是,在它被標記爲顯示之前發生的元素,但按鈕不是,踢球者是另一種模式是相同的但編輯而不是添加工作正常! –
當你看它時,這兩個元素在'DOM'中總是可見嗎? – Brian