5

I am trying to click the button labled "Pickup" at the following link :

https://firehouse.alohaorderonline.com/StartOrder.aspx?SelectMenuType=Retail&SelectMenu=1000560&SelectSite=01291

My code is below but does nothing until it fails with the error

element not interactable

pickupurl = 'https://firehouse.alohaorderonline.com/StartOrder.aspx?SelectMenuType=Retail&SelectMenu=1000560&SelectSite=1291'

driver = webdriver.Chrome('d:\\chromedriver\\chromedriver.exe')
driver.implicitly_wait(80)
driver.get(pickupurl)



button = driver.find_elements_by_xpath('//*[@id="ctl00_ctl00_PickupButton"]')
button.click()

The code appears to locate an element as when I print 'button' I get an element object.

I've tried using driver.execute_script to execute the onclick= attribute but this does nothing as well.

Any help is appreciated.

1
  • You asked if you had the wrong element... you were doing want the onClick of the JS would have done... but the main issue I think is, you are using find_elements_by_xpath you should use find_element_by_xpath without the "S"... Commented Jan 1, 2019 at 15:17

2 Answers 2

4

Using WebDriverWait and expected_conditions is a good practice!

see explicit-waits.

This works for me:

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

pickupurl = 'https://firehouse.alohaorderonline.com/StartOrder.aspx?SelectMenuType=Retail&SelectMenu=1000560&SelectSite=1291'
driver = webdriver.Chrome('d:\\chromedriver\\chromedriver.exe')
driver.get(pickupurl)
wait = WebDriverWait(driver, 10)
pickup_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@id='btnPickupDiv']/div[@class='Button']")))

pickup_button.click()
loacter = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "AddressZipLabelDiv")))
driver.quit()

The issue you had probably had something to do with find_elements_by_xpath you should use find_element_by_xpath without the s...

Sign up to request clarification or add additional context in comments.

Comments

3

The following works for me

from selenium import webdriver

d = webdriver.Chrome()
url = 'https://firehouse.alohaorderonline.com/StartOrder.aspx?SelectMenuType=Retail&SelectMenu=1000560&SelectSite=01291'
d.get(url)
d.execute_script('document.getElementById("ctl00_ctl00_Content_Content_btnPickup").click();')

Helpful warning from @Andersson

element.click() executed via execute_script doesn't really makes a click, but just triggers onclick action of element (link, input, button, etc). So if you're using this approach for web-testing you might miss tons of bugs

6 Comments

this works too! I do think it is better to use the find_element methods of webdriver rather than execute_script correct me if I'm wrong...
Thanks that did it. Was I simply not locating the right element?
And again you should warn OP about possible drawbacks of using execute_script to click element. If OP is engaged in web-application testing - this approach should not be used!
@Andersson I am a python newbie so appreciate any advice and more info on that warning.
@MosheSlavin's answer should be accepted instead of this one,
|

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.