问题
I am attempting to automate the checkout of a product on this website. However, at the very last step when a button is supposed to be clicked to submit the payment, the button just loads and the payment is neither completed nor declined (Pop up expected to tell the user that it has been declined).
As you can see below by the picture, the order information just keeps "loading" or "spinning" indefinitely.
I am not sure why this is happening. Any help would be appreciated.
Edit: I've used an explicit wait to wait for the dynamic content to load (i.e. HTML now matches the expected HTML of fully loaded page (i.e.
<button type="submit" title="Place Order" class="button btn-checkout" onclick="review.save();"><span><span>Place Order</span></span></button>
now exists, but it is still loading indefinitely. I'm not sure which other elements to wait for.
回答1:
If you are facing problem with the order on the mentioned site then please make sure that site do not have different behavior while you do checkout with the same details, manually.
While i have tried guest user checkout on same site i have faced connection timeout error in below API
POST https://www.converse.ca/braintree/checkout/quoteTotal/ net::ERR_CONNECTION_TIMED_OUT
Which causing that spinner continue rolling.
If there is element specific issue then you can handle that. Best usecase for the placing order are
While it lands on Order Review section you have to use explicit wait condition whether place or button is ready. refer below code
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "button[title='Place Order']")).click()
And then wait until spinner goes away to make sure order has been completed.
WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "review-please-wait"))
NOTE : Make sure your waiting time is sufficient for each section until info get loaded because there are some API call at the time you select some option. So it can cause your script failure because your script is fine but system is not ready.
回答2:
Did you used find_element_by_xpath()? In this case, give some implicit waiting time to get all the web resources. For example,
driver = wevdriver.Chrome()
driver.implicitly_wait(3)
driver.find_element_by_xpath().click()
来源:https://stackoverflow.com/questions/52676925/chrome-webdriver-unable-to-complete-product-checkout-automation