Python - send keys no funciona SELENIUM

 
Vista:
Imágen de perfil de Alejandro

send keys no funciona SELENIUM

Publicado por Alejandro (7 intervenciones) el 07/09/2023 20:02:55
Hola amigos estoy creando un programa automatizado de facturacion de compras en una tienda en especifico con python y selenium.

Todo iba viento en popa hasta que intente enviar cierta informacion a un formulario, dicho formulario lo encontre por xpath y luego utilice la funcion send keys para enviarle los datos desde los valores de un diccionario.
La cuestion es que hay dos formularios(razon social y calle) que no se llenan al correr el programa se quedan en blanco.

Creo que es un problema con los time.sleep que puse porque estuve jugando un poco con los tiempos y muy pocas veces se llego a llenar alguno de esos dos formularios, pero no logro conseguir que se llenen les dejo la seccion de codigo donde envio las instrucciones:

No tengo ningun tipo de problema con los demas formularios de la misma seccion solo con esos do formularios
dejo un video por si gustan ver el comportamiento y el repositorio de github por si gustan descargar mi codigo.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
 #ONCE THE TICKET WAS SUCCESSFULLY VALIDATED THE PROGRAM SEND THE TAX INFO TO THE PAGE
    tax_info = get_tax_information()
    print(tax_info)
    try:
        driver.find_element(By.XPATH, "//*[@id='form:rfc']").send_keys(tax_info.get("RFC"))
        time.sleep(5)
        driver.find_element(By.XPATH, "//*[@id='form:calle']").send_keys(tax_info.get("calle"))#NO SE LLENA
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:ext']").send_keys(tax_info.get("ext"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:int']").send_keys(tax_info.get("int"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:colonia']").send_keys(tax_info.get("colonia"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:dele']").send_keys(tax_info.get("municipio"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:codigo']").send_keys(tax_info.get("codigoPostal"))
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:razon']")#NO SE LLENA
        radio_bt.click()#AQUI INTENTE PRIMERO HACERLE CLICK Y LUEGO LLENAR NO FUNCIONO
        radio_bt.send_keys(tax_info.get("razonSocial"))
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:estado_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:estado_panel']/div/ul/li[23]")
        radio_bt.click()
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuRegFis_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuRegFis_panel']/div/ul/li[2]")
        radio_bt.click()
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuCFDI_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuCFDI_panel']/div/ul/li[9]")
        radio_bt.click()
        time.sleep(1)
    except:
        logFlow(8)
    else:
        print("TODO CHIDO")


PROYECTO:
https://github.com/al3xSpartan117/FacturacionOxxoProject/tree/main

LA PAGINA DONDE HAGO LAS FACTURAS:
https://www4.oxxo.com:9443/facturacionElectronica-web/views/layout/inicio.do


El codigo completo de la funcion donde se intenta llenar los formularios:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
def making_bill(billing_info):
    billing_info = billing_info.split("-")
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
    logFlow(2, billing_info)
    driver.get("https://www4.oxxo.com:9443/facturacionElectronica-web/views/layout/inicio.do")
    time.sleep(5)
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:dlgInfoTicket']/div[1]/a")
    radio_bt.click()#CLOSE INFO TICKET
    #time.sleep(1)
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:fecha_input']")
    radio_bt.click()#OPEN DATE INPUT BOX
    #time.sleep(1)
    radio_bt = driver.find_element(By.XPATH, "//*[@id='ui-datepicker-div']/div/a[1]/span")
    radio_bt.click()#CHANGE FROM SEPTEMBER TO AUGUST
    #In the next lineS select the day
    day_position = check_day(billing_info[0])#BILLING INFO 0 IS THE DATE
    radio_bt = driver.find_element(By.XPATH, "//*[@id='ui-datepicker-div']/table/tbody/tr[" + day_position[0] + "]/td[" + day_position[1] +"]")
    radio_bt.click()
    #Send information
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:folio']").send_keys(billing_info[1])
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:venta']").send_keys(billing_info[2])
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:total']").send_keys(billing_info[3])
    logFlow(3)
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:j_idt149']/span")
    radio_bt.click()#VALIDATE TICKET
    time.sleep(2)
    #THE NEXT LINES ARE TO VERIFY IF THE DELETE TICKET BUTTON IS IN THE PAGE THAT MEANS THE TICKET WAS SUCCESFULLY VALIDATED
    try:
        logFlow(4)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:tblTickets:0:j_idt137']")
    except:
        print("NO SE HA PODIDO AGREGAR LA FACTURA")
        logFlow(5, billing_info)
        save_invoice_to_reverify(billing_info)
    else:
        logFlow(6)
    #CLICK ON CONTINUE BUTTON
    radio_bt = driver.find_element(By.XPATH, "//*[@id='form:continuar']/span")
    radio_bt.click()
    time.sleep(2)
    #ONCE THE TICKET WAS SUCCESSFULLY VALIDATED THE PROGRAM SEND THE TAX INFO TO THE PAGE
    tax_info = get_tax_information()
    print(tax_info)
    try:
        driver.find_element(By.XPATH, "//*[@id='form:rfc']").send_keys(tax_info.get("RFC"))
        time.sleep(5)
        driver.find_element(By.XPATH, "//*[@id='form:calle']").send_keys(tax_info.get("calle"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:ext']").send_keys(tax_info.get("ext"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:int']").send_keys(tax_info.get("int"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:colonia']").send_keys(tax_info.get("colonia"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:dele']").send_keys(tax_info.get("municipio"))
        time.sleep(1)
        driver.find_element(By.XPATH, "//*[@id='form:codigo']").send_keys(tax_info.get("codigoPostal"))
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:razon']")
        radio_bt.click()
        radio_bt.send_keys(tax_info.get("razonSocial"))
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:estado_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:estado_panel']/div/ul/li[23]")
        radio_bt.click()
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuRegFis_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuRegFis_panel']/div/ul/li[2]")
        radio_bt.click()
        time.sleep(1)
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuCFDI_label']")
        radio_bt.click()
        radio_bt = driver.find_element(By.XPATH, "//*[@id='form:selectOneMenuCFDI_panel']/div/ul/li[9]")
        radio_bt.click()
        time.sleep(1)
    except:
        logFlow(8)
    else:
        print("TODO CHIDO")
    time.sleep(2)
    driver.close()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

send keys no funciona SELENIUM

Publicado por Costero (92 intervenciones) el 08/09/2023 06:22:03
Pon un sleep despues del click. A mi me funciona. Porque no se.

1
2
3
4
5
radio_bt = driver.find_element(By.XPATH, "//*[@id='form:razon']")
        radio_bt.click()
        time.sleep(1)
        radio_bt.send_keys(tax_info.get("razonSocial"))

Suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
Imágen de perfil de Alejandro

send keys no funciona SELENIUM

Publicado por Alejandro (7 intervenciones) el 12/09/2023 18:56:52
Muchas gracias amigo ya funciona
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar