Python: how to check the box with a browser splinter?

As soon as I add the following product to the cart: http://www.supremenewyork.com/shop/accessories/wau85w4km/cxv3ybp1w and go to the checkout page: https://www.supremenewyork.com/checkout , there is a check box for the conditions that I trying to execute using Browser's splinter , but Im not able to do this:

eg. I tried the following, but everyone ran into an error:

 from splinter import Browser browser = Browser("chrome") browser.find_by_id('order_terms').click() #Error: selenium.common.exceptions.WebDriverException: Message: unknown error browser.check('order[terms]').click() #Error: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible browser.find_by_name('order[terms]').click() #Error: selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 

What can i do wrong? And how can I check the checkbox with Browser splinter ?

Thank you in advance and be sure to confirm / accept the answer.

+5
source share
1 answer

Two main things to note:

  • to avoid synchronization problems, you need to โ€œseeโ€ explicitly in your script - expecting the elements to be visible or present before proceeding with the next steps.
  • this flag can and should be clicked by clicking on the entire label element containing input and other auxiliary elements

Here is the complete code:

 from splinter import Browser browser = Browser("chrome") browser.visit("http://www.supremenewyork.com/shop/accessories/wau85w4km/cxv3ybp1w") browser.wait_time = 10 try: browser.is_element_visible_by_css("input[name=commit]", 10) browser.find_by_css("input[name=commit]").first.click() browser.is_element_visible_by_css("a.checkout", 10) browser.find_by_css("a.checkout").first.click() browser.is_element_present_by_css("label.terms", 10) browser.find_by_css('label.terms').click() finally: browser.quit() 

Here is the working code that goes to the main page, goes to the third product in the scroller, adds it to the basket, checks and accepts the terms of use, time.sleep() at the end is just the result for you:

 from splinter import Browser browser = Browser("chrome") browser.visit("http://www.supremenewyork.com/shop") browser.wait_time = 10 try: # open a product browser.is_element_visible_by_css("#shop-scroller > li > a", 10) browser.find_by_css("#shop-scroller > li > a")[2].click() # add to cart browser.is_element_visible_by_css("input[name=commit]", 10) browser.find_by_css("input[name=commit]").first.click() # checkout browser.is_element_visible_by_css("a.checkout", 10) browser.find_by_css("a.checkout").first.click() # accept terms and conditions browser.is_element_present_by_css("label.terms", 10) browser.find_by_css('label.terms').click() import time time.sleep(10) finally: browser.quit() 
+2
source

Source: https://habr.com/ru/post/1273776/


All Articles