Reputation: 3760
I just can't make the button click and go the the next page. I tried the following so far
<div class="step__footer">
<button class="step__footer__continue-btn btn " type="submit" name="button">
<span class="btn__content">Continue to payment method</span>
<i class="btn__spinner icon icon--button-spinner"></i>
</button>
<a class="step__footer__previous-link" href="https://checkout.shopify.com/946304/checkouts/1b6e3391268707abb18850300b89e59?step=contact_information">
<svg class="previous-link__icon icon--chevron icon" viewBox="0 0 6.7 11.3" height="11.3" width="6.7" xmlns="http://www.w3.org/2000/svg">
Return to customer information
</a>
</div>
driver = webdriver.Firefox()
driver.implicitly_wait(1) # seconds
driver.find_element_by_css_selector("step__footer__continue-btn btn").click()
driver.implicitly_wait(1) # seconds
driver.find_element_by_xpath("/html/body/div[2]/div/div[2]/div[2]/div/form/div[2]/button").click()
driver.implicitly_wait(1) # seconds
driver.find_element_by_name("button").click()
driver.implicitly_wait(1) # seconds
elem.send_keys(Keys.RETURN)
driver.implicitly_wait(1) # seconds
driver.find_element_by_css_selector("div.step__footer>button").click()
driver.implicitly_wait(1) # seconds
driver.find_element_by_css_selector("html.multi-step.mac.firefox.desktop.page--no-banner.page--logo-main.page--show.js.flexbox.flexboxlegacy.rgba.multiplebgs.boxshadow.opacity.cssanimations.csstransitions.generatedcontent.svg.inlinesvg.cors.boxsizing.display-table.pointerevents.placeholder.mediaqueries.floating-labels body div.content div.wrap div.main div.main__content div.step form.edit_checkout.animate-floating-labels div.step__footer button.step__footer__continue-btn.btn").click()
driver.implicitly_wait(1) # seconds
driver.find_element_by_link_text("Continue to payment method").click()
driver.implicitly_wait(1) # seconds
driver.find_elements_by_class_name("step__footer__continue-btn btn ").click()
driver.implicitly_wait(1) # seconds
driver.findElementByXpath("//div[@type='submit'][@name='button']").click();
EDIT
The key was to relocate the elements, to reload. Since I was clicking through a form, the underlying code changed.
the driver.find_element_by_xpath("//button[@type='submit'][@name='button']").click() could not find elements because of that. After reloading with driver.get ("%s/%s:%s" % (str(sys.argv[4]), str(sys.argv[2]), str(sys.argv[3]))) it worked.
Also look at the log in case some badly formatted command interrupts the flow.
Upvotes: 2
Views: 5137
Reputation: 50809
You have many mistakes in your selectors, try one of those
driver.find_element_by_css_selector(".step__footer__continue-btn.btn").click() # for class with css_selector you need '.' in the beginning
driver.find_element_by_class_name("step__footer__continue-btn").click() # by_class_name gets only one class
driver.find_element_by_xpath("//button[@type='submit'][@name='button']").click() # type='submit' and name='button' are <button> tag attributes, not div
You can also try using explicit wait
WebDriverWait(driver, 10).until(expected_conditions.visibility_of_element_located((By.class_name, "step__footer__continue-btn"))).click()
Edit
Sometimes button element area is wider than the element that can receive click. You can try to click on elements in "lower" level
driver.find_element_by_class_name("btn__content").click() # <span> tag
# or
driver.find_element_by_class_name("btn__spinner").click() # <i> tag
Upvotes: 1