2

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.

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

5 Comments

doesn't work for some reason. it won't jump to the next page. I tried all, including the explicit wait. maybe the page source is different than firebug shows. I try printing it with print(driver.page_source), but for some reason I can't see the log
thanks guy. I just tried again, still doesn't react. I am trying to print the source as the driver sees it. maybe it is different than what FireBug display when I examine it manually when the script stops at the step in question.
driver.find_elements_by_class_name("btn__content").click() # <span> tag AttributeError: 'list' object has no attribute 'click' driver.find_elements_by_class_name("btn__spinner").click() # <i> tag AttributeError: 'list' object has no attribute 'click' I will try your original entries again. The print(driver.page_source) command might have interrupted the script.
@Zsolt try using the updated driver.find_element methods with the explicit wait.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.