我使用Hound作为webdriver框架来利用Elixir中的Selenium。我在测试facebook账号的创建。在我填写了否定测试(firstname = Roberto,lastname =asdlkfj;)之后,我单击了submit,我试图得到一个错误,因为我没有正确的姓氏。问题是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```发布于 2020-01-23 08:02:23
使用search_element而不是find_element。如果成功,search_element将返回{: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"))https://stackoverflow.com/questions/59868259
复制相似问题