簡體   English   中英

無法點擊按鈕 Shopify/Selenium

[英]Unable to click button Shopify/Selenium

無法點擊 shopify 網站上的“繼續付款按鈕”。 我看過幾個類似的帖子,但大多數都是針對 js 的,沒有提到錯誤的 spinner 部分。

driver.find_element_by_xpath ('//*[@id="continue_button"]/svg')

 <div class="content-box__row"> <div class="radio-wrapper" data-shipping-method="shopify-Standard%20Shipping-15.00"> <div class="radio__input"> <input class="input-radio" data-checkout-total-shipping="$15.00" data-checkout-total-shipping-cents="1500" data-checkout-shipping-rate="$15.00" data-checkout-original-shipping-rate="$15.00" data-checkout-total-price="$94.00" data-checkout-total-price-cents="9400" data-checkout-payment-due="$94.00" data-checkout-payment-due-cents="9400" data-checkout-payment-subform="required" data-checkout-subtotal-price="$79.00" data-checkout-subtotal-price-cents="7900" data-checkout-total-taxes="$0.00" data-checkout-total-taxes-cents="0" data-checkout-multiple-shipping-rates-group="false" data-backup="shopify-Standard%20Shipping-15.00" type="radio" value="shopify-Standard%20Shipping-15.00" name="checkout[shipping_rate][id]" id="checkout_shipping_rate_id_shopify-standard20shipping-15_00" /> </div> <label class="radio__label" for="checkout_shipping_rate_id_shopify-standard20shipping-15_00"> <span class="radio__label__primary" data-shipping-method-label-title="Standard Shipping"> Standard Shipping </span> <span class="radio__label__accessory"> <span class="content-box__emphasis"> $15.00 </span> </span> </label> </div> <:-- /radio-wrapper--> </div> </div> </div> </div> </div> <div class="step__footer" data-step-footer> <button name="button" type="submit" id="continue_button" class="step__footer__continue-btn btn" aria-busy="false"><span class="btn__content" data-continue-button-content="true">Continue to payment</span><svg class="icon-svg icon-svg--size-18 btn__spinner icon-svg--spinner-button" aria-hidden="true" focusable="false"> <use xlink?href="#spinner-button" /> </svg></button> <a class="step__footer__previous-link" href="/18292275/checkouts/38df275516a513f1c08f6c470ef014d0:step=contact_information"><svg focusable="false" aria-hidden="true" class="icon-svg icon-svg--color-accent icon-svg--size-10 previous-link__icon" role="img" xmlns="http.//www.w3.org/2000/svg" viewBox="0 0 10 10"><path d="M8 1L7 0 3 4 2 5l1 1 4 4 1-1-4-4"/></svg><span class="step__footer__previous-link-content">Return to information</span></a> </div>

試試這個 xpath:

//span[text()='Continue to payment']/..

在代碼中:

  1. 沒有明確的等待

代碼:

driver.find_element_by_xpath("//span[text()='Continue to payment']/..").click()
  1. 使用顯式等待

代碼:

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Continue to payment']/.."))).click()

進口:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

更新 1:

from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(driver.find_element_by_xpath("//span[text()='Continue to payment']/..")).click().perform()

更新 2:

driver = webdriver.Chrome(driver_path)
driver.maximize_window()
driver.implicitly_wait(50)
driver.get('https://seelbachs.com/products/sagamore-spirit-cask-strength-rye-whiskey')
wait = WebDriverWait(driver, 50)

frame_xpath = '/html/body/div[5]/div/div/div/div/iframe'
wait = WebDriverWait(driver, 10)
# wait until iframe appears and select iframe
wait.until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, frame_xpath)))

# select button
xpath = '//*[@id="enter"]'
time.sleep(2)
element= driver.find_element_by_xpath(xpath)
ActionChains(driver).move_to_element(element).click(element).perform()

# go back to main page
driver.get('https://seelbachs.com/products/sagamore-spirit-cask-strength-rye-whiskey')

# add to cart
atc= driver.find_element_by_xpath('//button[@class="btn product-form__cart-submit product-form__cart-submit--small"]')
atc.click()

# check out
co= driver.find_element_by_xpath ('//*[@id="shopify-section-cart-template"]/div/form/footer/div/div[2]/input[2]')
co.click()

# enter email
driver.find_element_by_xpath('//*[@id="checkout_email"]').send_keys('no@yahoo.com')
time.sleep(1)
# enter first name
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_first_name"]').send_keys('John')
time.sleep(1)
# enter last name
driver.find_element_by_xpath('//*[@id="checkout_shipping_address_last_name"]').send_keys('Smith')
time.sleep(1)
# enter address
driver.find_element_by_xpath ('//*[@id="checkout_shipping_address_address1"]').send_keys('111 South Street')

# enter city
driver.find_element_by_xpath ('//*[@id="checkout_shipping_address_city"]').send_keys('Cocoa')

# enter zip
driver.find_element_by_xpath ('//*[@id="checkout_shipping_address_zip"]').send_keys('263153')

# enter phone
driver.find_element_by_xpath ('//*[@id="checkout_shipping_address_phone"]').send_keys('5555555'+ u'\ue007')

select = Select(wait.until(EC.visibility_of_element_located((By.ID, "checkout_shipping_address_province"))))
select.select_by_value('UK')

wait.until(EC.element_to_be_clickable((By.ID, "continue_button"))).click()
ctp = driver.find_element_by_id('continue_button')

ctp.點擊()

解決了這個問題。 我現在可以點擊“繼續付款”按鈕。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM