skip to Main Content

javascript code (repeat order 1):

<div class="col-ea-1 repeat-order repeatable-order">  #common row in other snippets
 <button data-order-group-id="a9755447-04ff-4d00-59bf-06ff87f8ead6" #different row 
 data-restaurant-seo-url="/abc-pizza-bayburt-kirazli-mah" 
 class="ys-btn ys-btn-primary ys-btn-aa middle repeat-order-button"> REPEAT ORDER </button> ==$0
</div>

In the above snippet javascript code, there is more than one for each order (button data-order-group-id is different for each order) I also want to reach and click the REPEAT ORDER button for each order How can I do this in this piece of code?

2

Answers


  1. Chosen as BEST ANSWER

    @cruisepandey your code is working well but due to the website's specific conditions which are help center fixed box and ORDER REPEAT buttons can overlap somehow That's why I used "window.scrollTo" before in addition to your code

    i=int(input("choose:"))
       
    if i==0:
                      driver.execute_script("window.scrollTo(0, 300)") #move the area 
                      driver.find_elements(By.XPATH, "//button[contains(text(), 'REPEAT ORDER') and contains(@class, 'repeat-order-button')]")[0].click()
                      sleep(7)
    elif i==1:      
                      driver.execute_script("window.scrollTo(0, 300)") #move the area 
                      driver.find_elements(By.XPATH, "//button[contains(text(), 'REPEAT ORDER') and contains(@class, 'repeat-order-button')]")[1].click()
                      sleep(7)
    elif i==2:
                      driver.execute_script("window.scrollTo(0, 600)") #move the area   
                      driver.find_elements(By.XPATH, "//button[contains(text(), 'REPEAT ORDER') and contains(@class, 'repeat-order-button')]")[2].click()
                      sleep(7)
    

  2. You can try with the below xpath :

    //button[contains(text(), 'REPEAT ORDER') and contains(@class, 'repeat-order-button')]
    

    using find_element for single row, and find_elements for multiple row.

    sample code :

    for ele in driver.find_elements(By.XPATH, "//button[contains(text(), 'REPEAT ORDER') and contains(@class, 'repeat-order-button')]"):
        ele.click()
        # do some other stuff
        # re-initiate elements here otherwise you will get stale element reference
        #break if requires
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search