I want to know if there is any way to handle any type of error that appears in the browser so that within my function Connections (url) any object not found by the ccs_selector
instead of cutting the program back to run from the beginning def connections.
I had thought something like this:
try:
a = 12
b = 13
c = 14
except:
run(a)
I know that there is not that what I wrote but it is a way to graph what I am looking for. If for any reason I can not generate a = 12, b = 13, c = 14 try again! In the case of my code would be serious if any action within def could not be specified re-execute def
def Connections(url):
df = pd.read_excel(">0.20 fillrate.xlsx", header = None, converters={0: str}).pivot(columns = 0, values = 1)
Lista = {col: df[col].dropna().tolist() for col in df.columns}
for id, tags in Lista.iteritems():
urlcn = driver.get(url.format(id.strip()))
driver.refresh()
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")
try:
nombre2 = driver.find_element_by_css_selector('.select2-results-dept-0').click()
except:
pass
nombre.clear()
try:
driver.find_element_by_css_selector('button.btn-success:nth-child(3)').click()
except:
pass
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")
d= driver.current_url
time.sleep(5)
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)
print(d)
time.sleep(5)
driver.refresh()
time.sleep(5)