Вы можете настроить цикл while
, который будет разорван, как только будет найден WebElement, отвечающий определенным критериям.
# Keep track of whether or not invoice has been found
found = false
# First, attempt to locate the desired invoice
begin
# click the search button
driver.find_element(:name, "search_button").click
# check if invoice exists, set found to true if it does
expect(driver.find_element(some_locator_here).displayed?).to eql true
found = true
rescue Selenium::WebDriver::Error::NoSuchElementError
# catch NoSuchElementError if invoice does not exist, leave found as false
puts("Element not found")
# if invoice is not found, continue trying to find it in a loop
while found == false do
begin
# click the search button
driver.find_element(:name, "search_button").click
# attempt to locate the invoice
expect(driver.find_element(some_locator_here).displayed?).to eql true
found = true
rescue Selenium::WebDriver::Error::NoSuchElementError
puts("Element not found")
При нажатии кнопки поиска будет предпринята попытка найти нужный счет в цикле,затем поймайте NoSuchElementError
, если требуемый счет не существует. Вам нужно будет заменить some_locator_here
на что-то вроде :name, "invoice_name"
, чтобы вы могли найти свой счет и определить, был ли он найден. Надеюсь, это немного поможет.