Вы можете подождать, пока загрузочный счетчик больше не появится на странице, прежде чем проверять ввод кредитной карты.У нас есть решение на C #, которое вы можете попробовать адаптировать к python, где вы ожидаете в цикле отображения элемента, перехватывая исключения до достижения времени ожидания.
//Assert an element is displayed before the timeout milliseconds run out.
public void AssertElementIsDisplayed(int timeout, IWebElement element, string elementName = "element")
{
Action<IWebElement> target = delegate (IWebElement e) {
if (e == null)
{
throw new AssertionException("Failed to find " + elementName + ". It is null");
}
if (!e.Displayed)
{
elementName = (elementName == "element" && !String.IsNullOrEmpty(e.GetAttribute("title"))) ? e.GetAttribute("title") : elementName;
throw new AssertionException("Expected (" + elementName + ") to be displayed but it was not");
}
};
AssertInLoop(element, (long)timeout, 100L, target);
}
//Assert some Action on a WebElement for as long as the timeoutMillis allow.
private void AssertInLoop(IWebElement element, long timeoutMillis, long millisBetweenAttempts, Action<IWebElement> callable)
{
AssertionException lastAssertionError = null;
WebDriverException lastWebDriverException = null;
long startTime = DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond;
if (timeoutMillis < 500 || timeoutMillis > 120 * 1000)
{
throw new ArgumentException("Timeout outside expected range. timeout_millis=" + timeoutMillis);
}
long millisLeft = timeoutMillis;
while (millisLeft >= 1)
{
long lastAttemptStartMillis = DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond;
try
{
callable(element);
return;
}
catch (AssertionException e)
{
lastAssertionError = e;
lastWebDriverException = null;
}
catch (StaleElementReferenceException e)
{
lastAssertionError = null;
lastWebDriverException = e;
}
catch (NotFoundException e)
{
lastAssertionError = null;
lastWebDriverException = e;
}
catch (SystemException e)
{
throw e;
}
long elapsedMillis = (DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond) - startTime;
millisLeft = timeoutMillis - elapsedMillis;
if (millisLeft >= 1)
{
long millisElapsedDuringThisAttempt = (DateTimeOffset.Now.Ticks / TimeSpan.TicksPerMillisecond) - lastAttemptStartMillis;
long millisToSleep = millisBetweenAttempts - millisElapsedDuringThisAttempt;
if (millisToSleep > 0)
{
Thread.Sleep((int)millisToSleep);
}
}
}
if (lastAssertionError != null)
{
throw lastAssertionError;
}
else if (lastWebDriverException != null)
{
throw lastWebDriverException;
}
}