Quiero hacer este codigo con funciones. Con la data del Login ya lo logre y se loguea perfecto, el problema viene despues con 2 cuestiones:
La primera, donde dice #Clonar
hay un cambio de URL y se ejecuta automaticamente una vez que hago el click para loguearme. Eso hace que no termine de loguearse por eso necesitaria una funcion que no sea time.sleep()
sino una que espere a que el login termine o que cuando "onevideo.aol.com/#/Campaigns"
sea la pagina donde me encuentro en selenium(luego del login ingresa a esa url) ahi se ejecute mi driver.get("https://onevideo.aol.com/#/inventorysources")
.
Por otro lado, aca va mi segunda cuestion. Necesito tal como hice para el login hacer lo mismo con #Clonar, #Nombre tag, #Rate, #Floor. A que me refiero con 'Lo mismo', es que para ir ejecutando cada paso hasta que no obtenga la respuesta no ejecute el siguiente
Gracias
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome('/Users/Martin/Desktop/chromedriver')
driver.get("https://onevideo.aol.com/#/")
timeout = 30
def login():
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "input.ng-valid:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
username = driver.find_element_by_css_selector("input.ng-valid:nth-child(1)")
username.send_keys("martinbouhier")
driver.find_element_by_css_selector("button.btn:nth-child(2)").click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.group-field-block:nth-child(2) > input:nth-child(2)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
password = driver.find_element_by_css_selector("div.group-field-block:nth-child(2) > input:nth-child(2)")
password.send_keys("pass")
driver.find_element_by_css_selector(".button").click()
#Clonar
driver.get("https://onevideo.aol.com/#/inventorysources")
clone = driver.find_element_by_css_selector('div.ngRow:nth-child(1) > div:nth-child(1) > div:nth-child(9) > div:nth-child(1) > div:nth-child(1) > adap-options-menu:nth-child(1) > div:nth-child(1) > button:nth-child(2)').click()
clone = driver.find_element_by_css_selector('.open > ul:nth-child(5) > li:nth-child(3) > a:nth-child(1)').click()
#Nombre tag
name = driver.find_element_by_css_selector('div.margin-top-medium > input:nth-child(1)')
name.clear()
name.send_keys('--test$2--')
#Rate
Rate = driver.find_element_by_css_selector('.span9 > div:nth-child(1) > form:nth-child(1) > div:nth-child(9) > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > span:nth-child(1) > adap-input:nth-child(1) > span:nth-child(1) > input:nth-child(2)')
Rate.clear()
Rate.send_keys('2')
#Floor
Floor = driver.find_element_by_css_selector('.span9 > div:nth-child(1) > form:nth-child(1) > div:nth-child(12) > div:nth-child(2) > adap-input:nth-child(1) > span:nth-child(1) > input:nth-child(1)')
Floor.clear()
Floor.send_keys('2')
driver.find_element_by_css_selector(".bs-docs-social-buttons > li:nth-child(2) > button:nth-child(1)").click()
driver.close()