Skip to main content
added 45 characters in body; edited title
Source Link
Michael Durrant
  • 25.2k
  • 3
  • 41
  • 113

Why does element.displayed? throws exception instead of boolean false?

Here's snippet of my code

while (!$driver.find_element(:xpath,element2).displayed?)
    $driver.find_element(:xpath,element1).click()
end

for some reason element.displayed? throws this exception:

An element could not be located on the page using the given search parameters. (RuntimeError)

i expectI expected the code to return false when the element iswas not found but instead I got the exception. is
Is this working as intended or i'mam I using it wrongincorrectly?

Why element.displayed? throws exception instead of boolean false?

Here's snippet of my code

while (!$driver.find_element(:xpath,element2).displayed?)
    $driver.find_element(:xpath,element1).click()
end

for some reason element.displayed? throws this exception:

An element could not be located on the page using the given search parameters. (RuntimeError)

i expect the code to return false when the element is not found. is this working as intended or i'm using it wrong?

Why does element.displayed? throws exception instead of boolean false?

Here's snippet of my code

while (!$driver.find_element(:xpath,element2).displayed?)
    $driver.find_element(:xpath,element1).click()
end

for some reason element.displayed? throws this exception:

An element could not be located on the page using the given search parameters. (RuntimeError)

I expected the code to return false when the element was not found but instead I got the exception.
Is this working as intended or am I using it incorrectly?

Source Link

Why element.displayed? throws exception instead of boolean false?

Here's snippet of my code

while (!$driver.find_element(:xpath,element2).displayed?)
    $driver.find_element(:xpath,element1).click()
end

for some reason element.displayed? throws this exception:

An element could not be located on the page using the given search parameters. (RuntimeError)

i expect the code to return false when the element is not found. is this working as intended or i'm using it wrong?