Usa dict.iteritems
, primero usa la key para crear la url, posteriormente iteras sobre las tags de esa url y así por cada clave del diccionario:
Lista = {'829690' :['testmartin','--test$2--'],
'1016244':['camionetas','autos']}
for id, tags in Lista.iteritems():
url = driver.get("https://onevideo.aol.com/#/marketplaceconnection/{}".format(id.strip()))
# Codigo a ejecutar antes de pasar los tags
for tag in tags:
nombre.send_keys(tag)
Si te he entendido deberías hacer algo así:
def Target():
for id, tags in Lista.iteritems():
url = driver.get("https://onevideo.aol.com/#/marketplaceconnection/{}".format(id.strip()))
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar-inhiner > ul:nth-child(1) > li:nth-child(4) > a:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('.navbar-inhiner > ul:nth-child(1) > li:nth-child(4) > a:nth-child(1)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "li.ng-scope:nth-child(6) > a:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('li.ng-scope:nth-child(6) > a:nth-child(1)').click()
#Cargado de tags
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "span.ng-scope:nth-child(12) > div:nth-child(1) > span:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('span.ng-scope:nth-child(12) > div:nth-child(1) > span:nth-child(1)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "#s2id_autogen30"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
nombre = driver.find_element_by_css_selector('#s2id_autogen30')
for tag in tags:
nombre.send_keys(tag)
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, '.select2-results-dept-0'))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
nombre2 = driver.find_element_by_css_selector('.select2-results-dept-0').click()
driver.find_element_by_css_selector('button.btn-success:nth-child(3)').click()
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "div.modal-footer:nth-child(3) > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector('div.modal-footer:nth-child(3) > button:nth-child(1)').click()
#Guardado de la connection
try:
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, ".bs-docs-social-buttons > li:nth-child(2) > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
except TimeoutException:
print ("Timed out waiting for page to load")
driver.find_element_by_css_selector(".bs-docs-social-buttons > li:nth-child(2) > button:nth-child(1)").click()
element_present = EC.presence_of_element_located((By.CSS_SELECTOR, "adap-marketplace-connections-grid-filter.ng-scope > button:nth-child(1)"))
WebDriverWait(driver, timeout).until(element_present)
Al no poder acceder a la paǵina no se si todo está identado donde debe estar, pero la idea debe ser esta.
No deberías usar clases, tu aplicación sigue un paradigma estructurado no programación orientada a objetos. No tiene sentido crear un objeto que en realidad no es tal, solo ejecuta código. Usa funciones (def
) y las llamas en el main
como haces con las clases.