def test_Elementos_En_Tablas(self): driver = self.driver driver.maximize_window() driver.get("https://www.w3schools.com/html/html_tables.asp") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("HTML Tables", driver.title) time.sleep(3) valor = driver.find_element_by_xpath( "//*[@id='customers']/tbody/tr[2]/td[2]").text print("El resultado por elemento es: ", valor) time.sleep(3) rows = len( driver.find_elements_by_xpath("//*[@id='customers']/tbody/tr")) col = len( driver.find_elements_by_xpath( "//*[@id='customers']/tbody/tr[1]/th")) print("El resultado por elemento es: ", rows) print("El resultado por elemento es: ", col) print("El resultado es: ") for n in range(2, rows + 1): for b in range(1, col + 1): dato = driver.find_element_by_xpath( "//*[@id='customers']/tbody/tr[" + str(n) + "]/td[" + str(b) + "]").text print(" - ", dato, end=" ") print()
def test_boton_radio(self): driver = self.driver driver.maximize_window() driver.get("https://www.w3schools.com/howto/howto_css_custom_checkbox.asp") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("How To Create a Custom Checkbox", driver.title) time.sleep(3) boton_radio = driver.find_element_by_xpath("//*[@id='main']/div[3]/div[1]/input[4]") boton_radio.click() time.sleep(3) boton_radio = driver.find_element_by_xpath("//*[@id='main']/div[3]/div[1]/input[3]") boton_radio.click() time.sleep(3)
def test_Descargar_Archivo(self): driver = self.driver driver.maximize_window() driver.get( "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_a_download" ) time.sleep(5) print("Titulo de la aplicación: ", driver.title, "\n") print("URL de la aplicación: ", driver.current_url, "\n") self.assertIn("Tryit Editor v3.6", driver.title) driver.switch_to.frame( driver.find_element_by_xpath( "/html/body/div[7]/div[4]/div/div/iframe")) driver.find_element_by_xpath("/html/body/p[2]/a").click() #print("Satisfactorio", Movimiento) time.sleep(5)
def test_Confirm_Alert(self): driver = self.driver driver.maximize_window() driver.get("File:///C:/Users/ING/Desktop/Automation/Automation/Alertas/ConfirmAlert.html") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("Cofirmar Alerta", driver.title) time.sleep(3) Confirmar_Alerta = driver.find_element_by_xpath("/html/body/button") Confirmar_Alerta.click() time.sleep(3) Confirmar_Alerta = driver.switch_to_alert() Confirmar_Alerta.dismiss()#boton de cancelar o recharzar time.sleep(3) Confirmar_Alerta = driver.find_element_by_xpath("/html/body/button") Confirmar_Alerta.click() time.sleep(3) Confirmar_Alerta = driver.switch_to_alert() Confirmar_Alerta.accept()#boton de aceptar time.sleep(3)
def test_select(self): driver = self.driver driver.implicitly_wait(15) #pausa segundo driver.maximize_window() driver.get("https://www.w3schools.com/howto/howto_custom_select.asp") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("How To Create Custom Select Menus", driver.title) select = driver.find_element_by_xpath( "//*[@id='main']/div[3]/div[1]/select") opcion = select.find_elements_by_tag_name("option") #print("Funciona") time.sleep(3) for option in opcion: print("Los Valores Son: %s" % option.get_attribute("value")) option.click() time.sleep(1) seleccionar = Select( driver.find_element_by_xpath( "//*[@id='main']/div[3]/div[1]/select")) seleccionar.select_by_value("10") time.sleep(3)
def test_Buscar_Por_Xpath(self): driver = self.driver driver.get("http://www.google.com") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("Google", driver.title) #time.sleep(3) elemento = driver.find_element_by_xpath( "/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input" ) #print("FUNCIONA1") #time.sleep(3) elemento.send_keys("selenium", Keys.ARROW_DOWN)
def test_toggle_switch(self): driver = self.driver driver.implicitly_wait(15) #pausa segundo driver.maximize_window() driver.get("https://www.w3schools.com/howto/howto_css_switch.asp") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("How To Create a Toggle Switch", driver.title) toggle = driver.find_element_by_xpath("//*[@id='main']/label[1]/div") toggle.click() print("Funciona") time.sleep(3) toggle.click() time.sleep(3)
def test_Alert_Simple(self): driver = self.driver driver.maximize_window() driver.get( "File:///C:/Users/ING/Desktop/Automation/Automation/Alertas/AlertSimple.html" ) print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("Alerta Simple", driver.title) time.sleep(3) Alerta_Simple = driver.find_element_by_xpath("/html/body/button") Alerta_Simple.click() time.sleep(3) Alerta_Simple = driver.switch_to_alert() Alerta_Simple.dismiss() time.sleep(3)
def test_Display_Element(self): driver = self.driver driver.maximize_window() driver.get("https://www.google.com") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("Google", driver.title) time.sleep(3) displayelement = driver.find_element_by_xpath( "/html/body/div[1]/div[3]/form/div[1]/div[1]/div[3]/center/input[2]" ) print("Cargo el elemento: ", displayelement.is_displayed() ) #regresa true o false si ya cargo el elemento print("Esta disponible: ", displayelement.is_enabled() ) #regresa true o false si el elemento esta disponible time.sleep(3)
def test_Hyperlinks(self): driver = self.driver driver.maximize_window() driver.get("https://www.w3schools.com/") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("W3Schools Online Web Tutorials", driver.title) time.sleep(5) #encontrar1 = driver.find_element_by_link_text('Tutorials') #encontrar1.click() encontrar1 = driver.find_element_by_xpath( '//*[@id="navbtn_tutorials"]') encontrar1.click() time.sleep(3) encontrar = driver.find_element_by_link_text('Learn PHP') encontrar.click() time.sleep(3)
def test_Cortar_Imagen(self): driver = self.driver driver.maximize_window() driver.get("https://www.google.com") print("Titulo de la aplicación: ", driver.title, "\n") print("URL de la aplicación: ", driver.current_url, "\n") self.assertIn("Google", driver.title) time.sleep(2) imagen = driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/img") imagen_encontrada = imagen.location tamaño = imagen.size G_imagen = driver.get_screenshot_as_png() imagen2 = Image.open(BytesIO(G_imagen)) left = imagen_encontrada['x'] top = imagen_encontrada['y'] right = imagen_encontrada['x'] + tamaño ['width'] boton = imagen_encontrada['x'] + tamaño ['height'] imagen2 = imagen2.crop((left, top, right, boton)) imagen2.save('Mi_logo_prueba.png')
def test_Recuperador_busqueda(self): driver = self.driver driver.maximize_window() driver.get("https://www.google.com") print("Titulo de la aplicación: ", driver.title) print("URL de la aplicación: ", driver.current_url) self.assertIn("Google", driver.title) time.sleep(5) palabra_busqueda = 'Sele' elemento = driver.find_element_by_name('q') elemento.send_keys(palabra_busqueda) time.sleep(3) #print("funciona") for i in range(1, 11): #print("funciona") elementos = driver.find_element_by_xpath( "/html/body/div[1]/div[3]/form/div[1]/div[1]/div[2]/div[2]/ul/li[" + str(i) + "]/div/div[2]/div[1]/span").text print("La busqueda es: ", elementos)
def test_Iframe_Frame(self): driver = self.driver driver.maximize_window() driver.get("https://www.google.com") time.sleep(5) print("Titulo de la aplicación: ", driver.title, "\n") print("URL de la aplicación: ", driver.current_url, "\n") self.assertIn("Google", driver.title) Click = self.driver.find_element_by_xpath("//*[@id='gbwa']") Click.click() time.sleep(5) driver.switch_to.frame( driver.find_element_by_xpath( "/html/body/div[1]/div[1]/div/div/div/div[3]/iframe")) Click2 = self.driver.find_element_by_xpath( "//*[@id='yDmH0d']/c-wiz/div/div/c-wiz/div/div/ul[1]/li[4]/a/div/span" ) Click2.click() #print("Satisfactorio", Movimiento) time.sleep(5)
def test_Portal_De_Viajes(self): driver = self.driver driver.maximize_window() driver.get("https://www.bestday.com.mx") print("Titulo de la aplicación: ", driver.title, "\n") print("URL de la aplicación: ", driver.current_url, "\n") self.assertIn( "Best Day - Agencia de Viajes: Vuelos, hoteles, paquetes", driver.title) time.sleep(2) #Ciudad de origen cdorigen = driver.find_element_by_xpath( "//*[@id='sboxContainer-packages']/div/div/div[3]/div[2]/div[2]/div[1]/div/div/div/input" ) cdorigen.send_keys("Bogotá, Bogotá D.C., Colombia") time.sleep(2) cdorigen.send_keys(Keys.TAB) time.sleep(2) #Ciudad de Destino cddestino = driver.find_element_by_xpath( "//*[@id='sboxContainer-packages']/div/div/div[3]/div[2]/div[2]/div[2]/div/div/div/div/input" ) cddestino.send_keys("Barranquilla, Atlántico, Colombia") time.sleep(2) cddestino.send_keys(Keys.TAB) time.sleep(2) #DatePicker1 - ida datapicker = driver.find_element_by_xpath( "//*[@id='sboxContainer-packages']/div/div/div[3]/div[2]/div[3]/div/div[1]/div/input" ) datapicker.click() subirmes = driver.find_element_by_xpath( "/html/body/div[5]/div/div[2]/div[2]") subirmes.click() subirmes.click() subirmes.click() selectdia1 = driver.find_element_by_xpath( "/html/body/div[5]/div/div[5]/div[5]/div[4]/span[16]/span[1]") selectdia1.click() time.sleep(2) #DatePicker2 - vuelta selectdia2 = driver.find_element_by_xpath( "/html/body/div[5]/div/div[5]/div[5]/div[4]/span[23]/span[1]") selectdia2.click() time.sleep(2) #Aplicar DatePicker's aplicar = driver.find_element_by_xpath( "/html/body/div[7]/div/div[6]/div[2]/button[2]/em") aplicar.click() time.sleep(5) #Quitar anuncio promocional Alerta = driver.find_element_by_id("onesignal-slidedown-dialog") Alerta.click() NoGracias = driver.find_element_by_css_selector( "#onesignal-slidedown-cancel-button") NoGracias.click() time.sleep(10) #Seleccionar Habitacion habitacion = driver.find_element_by_xpath( "//*[@id='sboxContainer-packages']/div/div/div[3]/div[2]/div[5]/div" ) habitacion.click() time.sleep(5) #Seleccionar Adultos AdultosMas = driver.find_element_by_css_selector( "body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div:nth-child(1) > div._pnlpk-itemRow__item._pnlpk-stepper-adults.-medium-down-to-lg > div > a.steppers-icon-right.sbox-3-icon-plus" ) #AdultosMenos = driver.find_element_by_css_selector("body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div:nth-child(1) > div._pnlpk-itemRow__item._pnlpk-stepper-adults.-medium-down-to-lg > div > a.steppers-icon-left.sbox-3-icon-minus") AdultosMas.click() AdultosMas.click() #AdultosMenos.click() #AdultosMenos.click() time.sleep(3) #Seleccionar Menores MenoresMas = driver.find_element_by_css_selector( "body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div:nth-child(2) > div._pnlpk-itemRow__item._pnlpk-stepper-minors.-medium-down-to-lg > div > a.steppers-icon-right.sbox-3-icon-plus" ) #MenoresMenos = driver.find_element_by_css_selector("body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div:nth-child(2) > div._pnlpk-itemRow__item._pnlpk-stepper-minors.-medium-down-to-lg > div > a.steppers-icon-left.sbox-3-icon-minus.-disable") MenoresMas.click() MenoresMas.click() #MenoresMenos.click() #MenoresMenos.click() time.sleep(5) #Seleccionar Edad menor Solo si ahi menores #Para cada campo de menor de edad debe inspeccionar campo a campo EdadMenor1 = driver.find_element_by_css_selector( "body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div._pnlpk-minors-age-select-wrapper > div:nth-child(1) > div._pnlpk-itemRow__item._pnlpk-select-minor-age > div > div > select > option:nth-child(6)" ) time.sleep(2) try: EdadMenor1.click() print("Si se ejecuto") time.sleep(2) except WebDriverException as e: print("No se ejecuto el evento") print(e) time.sleep(2) return (116) EdadMenor2 = driver.find_element_by_css_selector( "body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel-scroll > div._pnlpk-panel__blocks._pnlpk-dynamicContent > div:nth-child(1) > div._pnlpk-itemBlock__itemRows > div._pnlpk-minors-age-select-wrapper > div._pnlpk-itemRow._pnlpk-minor-age-select._pnlpk-minor-age-select-last-item > div._pnlpk-itemRow__item._pnlpk-select-minor-age > div > div > select > option:nth-child(19)" ) EdadMenor2.click() time.sleep(5) #Aplicar Habitaciones aplicar2 = driver.find_element_by_css_selector( "body > div.distpicker.distpicker-rooms-packages.sbox-v4-components > div > div._pnlpk-panel__footer.-medium-down-to-lg > a._pnlpk-apply-button.sbox-3-btn.-primary._pnlpk-panel__button--link-right.-lg" ) aplicar2.click() time.sleep(5) #Buscar Buscar = driver.find_element_by_xpath( "//*[@id='sboxContainer-packages']/div/div/div[3]/div[2]/div[6]/div" ) Buscar.click() time.sleep(30)