2

I have tried to make my script click the checkout button with WebDriverWait, XPath, Class, but it doesn't work anyways :

HTML

<div class="confirm-container row">
    :before
    <div class="col-xs-12">
        <button class="btn btn-primary">
            <span>Effettua l'ordine</span>
        </button>
    </div>
    ::after
</div>

1st try

var = '//*[@id="purchase-app"]/div/div[4]/div[1]/div[2]/div[5]/div/div/button'
WebDriverWait(web, 50).until(EC.element_to_be_clickable((By.XPATH, var)))
web.find_element_by_xpath(var).click()

2nd try web.find_element_by_class_name('btn btn-primary').click()

3rd try ActionChains(web).click(web.find_element_by_class_name('btn btn-primary')).perform()

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
Jorge
  • 23
  • 3
  • I have'nt made a research about it, but when I tried to make selenium press something like a subscribe button in Youtube it didn't work, I figured Google might be making it harder to do automatially. Not sure though – איתן טורפז Jun 17 '21 at 11:15

2 Answers2

1

When you are using Explicit wait, try to have a relative xpath :

1st try issue can be resolved by the below code :

WebDriverWait(web, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Effettua l'ordine']/.."))).click()

2nd try web.find_element_by_class_name('btn btn-primary').click() - class name does not accept spaces so, use css selector instead :

web.find_element_by_css_selector('button.btn.btn-primary').click()

same issue with 3rd try.

Update 1 :

The issue is that, the button you are looking is in iframe so you need to switch over it before interaction :

Code :

wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR, "iframe[src^='/store/purchase?namespace']")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-primary"))).click()

Imports :

from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
0

You can try this

from selenium.webdriver import ActionChains
ActionChains(browser).click(element).perform()

while element refer to anything between the start tag and end tag.

as stated in the answer here: https://stackoverflow.com/a/61036237/11884764

Obaskly
  • 477
  • 2
  • 13