Skip to content

Instantly share code, notes, and snippets.

@RajatGoyal
Last active September 15, 2016 13:03
Show Gist options
  • Save RajatGoyal/f806a427d7bac3627a9accdb5b4bbf1c to your computer and use it in GitHub Desktop.
Save RajatGoyal/f806a427d7bac3627a9accdb5b4bbf1c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
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
import time, sys
username = 'gyl.rajat@gmail.com'
password = 'xxxxx'
driver = webdriver.Chrome()
def click_element_by_id(id, delay=0, timeout=15):
id_present = EC.presence_of_element_located((By.ID, id))
WebDriverWait(driver, timeout).until(id_present)
time.sleep(delay)
driver.find_element(By.ID,value=id).click()
def click_element_by_xpath(xpath, delay=0, element_index=0):
time.sleep(delay)
driver.find_elements_by_xpath(xpath)[element_index].click()
def login():
click_element_by_id('signin-link', 5)
click_element_by_id('login-email')
inputElement = driver.find_element_by_id("ld-email")
inputElement.send_keys(username)
inputElement = driver.find_element_by_id("ld-password")
inputElement.send_keys(password)
inputElement.submit()
def main():
restaurant_link = sys.argv[1]
main_dish = sys.argv[2]
options = sys.argv [3:]
driver.get(restaurant_link + "/order")
login()
click_element_by_xpath("//div[contains(text(), '{main_dish}')]/parent::div/following-sibling::div[1]/a".format(main_dish=main_dish), 6)
for option in options:
click_element_by_xpath("//label[contains(text(), '{option}')]".format(option=option), 1)
click_element_by_xpath("//div[contains(text(), 'Add To Cart')]", 6)
click_element_by_xpath("//button[contains(text(), 'Continue')]", 3)
click_element_by_xpath("//input[@type='radio']", 3)
click_element_by_xpath("//button[contains(text(), 'Continue')]", 3, 1)
click_element_by_xpath("//div[text() = 'Credit']", 3)
click_element_by_xpath("//button[contains(text(), 'Pay by Card')]", 2)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment