Skip to content

Instantly share code, notes, and snippets.

@pablocastelo
Created September 28, 2016 03:56
Show Gist options
  • Select an option

  • Save pablocastelo/e1078d543caeebc5edc71125f50229b7 to your computer and use it in GitHub Desktop.

Select an option

Save pablocastelo/e1078d543caeebc5edc71125f50229b7 to your computer and use it in GitHub Desktop.
Recargas automáticas a Amigo Telcel con tarjeta de crédito y selenium
from selenium import webdriver
from selenium.webdriver.support import ui
from selenium.webdriver.common.keys import Keys
import time
cargas = ['500', '300', '200', '150', '100', '50', '30', '20']
dict_cargas = {}
i = 0
for c in cargas:
i += 1
dict_cargas[c] = i
# pon tus datos aquí:
cargale = '50' # tu carga en string (ver variable cargas)
num = '55********' # número al que le quieres hacer la carga a 10 dígitos
cc = ["****","****","****","****"] # tu tarjeta de crédito
venc = [2,2021] # fecha de vencimiento en número
cvv2 = ['***'] # el número cvv2 al reverso de tu tarjeta
email = ['[email protected]'] # correo electrónico
cp = ['82017'] # tu código postal
def page_is_loaded(driver):
return driver.find_element_by_tag_name("body") != None
def form_is_loaded(driver):
return driver.find_element_by_tag_name("form") != None
def list_is_loaded(driver):
return driver.find_element_by_xpath("//input[@type='text']") != None
driver = webdriver.Chrome()
driver.get("https://mitelcel1.recarga.telcel.com/MiTelcelMXExternalWebAnonymous/enter.do?anonymous=true")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
wait.until(form_is_loaded)
# Primera sección - validación del teléfono
tel = driver.find_element_by_id("mdn")
tel.click()
tel.send_keys(num)
tel.send_keys(Keys.ENTER)
time.sleep(1)
telConf = driver.find_element_by_id("mdnConfirm")
telConf.send_keys(num)
telConf.send_keys(Keys.ENTER)
time.sleep(1)
wait.until(list_is_loaded)
driver.find_element_by_xpath("//a[@class='chosen-single']").click()
wAmount = driver.find_element_by_xpath("//li[@data-option-array-index='{}']".format(dict_cargas[cargale]))
wAmount.click()
driver.find_element_by_id("continue_button").click()
wait.until(page_is_loaded)
driver.find_element_by_id("submit_button").click()
wait.until(page_is_loaded)
i = 0
for c in cc:
i += 1
driver.find_element_by_name("num_card{}".format(i)).send_keys(c)
driver.find_element_by_xpath("(//*[@class='chosen-single'])[1]").click()
driver.find_element_by_xpath("(//*[@data-option-array-index='{}'])[1]".format(venc[0])).click()
driver.find_element_by_xpath("(//*[@class='chosen-single'])[2]").click()
driver.find_element_by_xpath("(//*[@data-option-array-index='{}'])[2]".format(venc[1] - 2015)).click()
driver.find_element_by_name("chargeCVN").send_keys(cvv2)
driver.find_element_by_name("postalCode").send_keys(cp)
driver.find_element_by_name("emailAddress").send_keys(email)
driver.find_element_by_id("continue_button").click()
driver.find_element_by_tag_name("body").send_keys(Keys.TAB)
driver.find_element_by_id("acheckbox").click()
goNext = driver.find_element_by_id("submit_button")
#goNext.click()
@ireyesb09-byte
Copy link

Desde el webdriver de Seleniumimport.
from selenium.webdriver.support import ui.
from selenium.webdriver.common.keys import a Keys.
Tiempo de importación.

Cargas = ['500', '300', '200', '150', '100', '50', '30', '20'].

dict_cargas = {}.
i = 0.
For cin cargas:
i += 1.
dict_cargas[c]= i.

pon tus datos aquí:

Cargale = '50' # tu carga en cadena (ver cargas variables).
Num = '55******' # número al que le quieres hacer la carga a 10 dígitos.
cc = ["**** ","****** ","****** ","**** "] # tu tarjeta de crédito.
Venc = [2,2021]# fecha de vencimiento en número.
CVV2 = ['***'] # el número CVV2 al reverso de tu tarjeta.
email = ['[email protected]'] # correo electrónico.
CP = ['82017'] # tu código postal.

def page_is_loaded (conductor):
Return driver.find_element_by_tag_name ("body ") != Ninguno.
def form_is_loaded (conductor):
Return driver.find_element_by_tag_name ("form ") != Ninguno.
def list_is_loaded (conductor):
Return driver.find_element_by_xpath ("/input[@type='text']"). != Ninguno.

driver = webdriver.Chrome ()
conductor.get ("https://mitelcel1.recarga.telcel.com/MiTelcelMXExternalWebAnonymous/enter.do?anonymous=true") .

wait = ui.WebDriverWait (conductor, 10)
espera.hasta que (page__is_loaded).
espera.hasta que (form_is_loaded).

Primera sección - validación del teléfono

tel = driver.find_element_by_id ("mdn ")
tel. haga clic () .
tel.send_keys (num) .
tel.send_keys (Keys.ENTER)
tiempo. sueño (1) .

telConf = driver.find_element_by_id ("mdnConfirmar ")
TelConf.send_keys (num) .
telConf.send_keys (Keys.ENTER)
tiempo. sueño (1) .

espera.hasta que (list_is_loaded).
driver.find_element_by_xpath ("//a[@Class='elegido-single'] "). haga clic ()

wAmount = driver.find_element_by_xpath ("//li[@data-option-array-index='{}} ".format (dict_cargas[cargale]) .
Cantidad. haga clic () .

driver.find_element_by_id ("continue_button "). haga clic ()

espera.hasta que (page__is_loaded).
driver.find_element_by_id ("submit_button "). haga clic ()

espera.hasta que (page__is_loaded).

i = 0.
For c in cc:
i += 1.
driver.find_element_by_name ("num_card{}".format (i)).send_keys (c) .

driver.find_element_by_xpath (" (//[@Class='elegido-single']) [1]"). haga clic ()
driver.find_element_by_xpath (" (//
[@data-option-array-index='{}') [1]".format (venc[0])). haga clic ()

driver.find_element_by_xpath (" (//[@Class='elegido-single']) [2]"). haga clic ()
driver.find_element_by_xpath (" (//
[@data-option-array-index='{}') [2]".format (venc[1] - 2015)).haga clic en ) .

driver.find_element_by_name ("chargeCVN").send_keys (cvv2)
driver.find_element_by_name ("postalCode ").send_keys (cp)
driver.find_element_by_name (emailAddress").send_keys (email)

driver.find_element_by_id ("continue_button "). haga clic ()

driver.find_element_by_tag_name ("body ").send_keys (Keys.TAB)

driver.find_element_by_id (chaque "a "). haga clic ()

goNext = driver.find_element_by_id ("submit_button ")
#goNext.click ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment