[英]How to assert an element is present after a click in Hound?
我使用 Hound 作為在 Elixir 中利用 Selenium 的 webdriver 框架。 我正在測試 Facebook 帳戶的創建。 在我填寫了一個否定測試(名字 = Roberto,姓氏 = asdlkfj;)后,我點擊提交,但我試圖因為沒有正確的姓氏而出現錯誤。 問題是 Hound 沒有等待元素被顯示並返回一個元素未找到錯誤。 我該如何處理並讓測試等待元素加載完成? 這是我的代碼:
test "Last name with random characters" do
counter = :rand.uniform(100)
navigate_to "https://www.facebook.com"
first_name = find_element(:name, "firstname")
fill_field(first_name, "Jorge")
last_name = find_element(:name, "lastname")
fill_field(last_name, "asdfja;lsdf")
email_input = "robbie#{counter}@gmail.com"
email = find_element(:name, "reg_email__")
fill_field(email, email_input)
confirm_email = find_element(:name, "reg_email_confirmation__")
fill_field(confirm_email, email_input)
password_input = "123456Test"
password = find_element(:name, "reg_passwd__")
fill_field(password, password_input)
#Birthday
birth_month = find_element(:css, "#month > option:nth-child(5)")
birth_day = find_element(:css, "#day > option:nth-child(25)")
birth_year = find_element(:css, "#year > option:nth-child(22)")
click(birth_month)
click(birth_day)
click(birth_year)
#gender
select_gender = find_element(:css, "#u_0_s > span:nth-child(2)")
click(select_gender)
sign_up_button = find_element(:name, "websubmit")
click(sign_up_button)
search = find_element(:id, "#reg_error_inner")
# found = element_displayed?("#reg_error_inner")
IO.puts(search)
# assert found == true
# :timer.sleep(10000)
end```
使用search_element
而不是find_element
。 search_element
將在成功時返回{:ok, element}
{:error, error}
在失敗時返回{:ok, element}
{:error, error}
。 如果您只想斷言元素存在,那么您可以:
assert {:ok, _} = search_element(:id, "#reg_error_inner")
如果您還想將其放在變量中以供進一步處理,則:
assert {:ok, element} = search_element(:id, "#reg_error_inner")
如果要將其轉換為布爾值,則:
match?({:ok, _}, search_element(:id, "#reg_error_inner"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.