- rsvore
- Posts : 4
Join date : 2012-11-08
Check for img alt and continue for loop
Thu Nov 08, 2012 8:18 pm
I have a for loop and I need to check id an img alt text is open. if not I don't want the loop to timeout but continue to the next number to look up. How can i do this? I'm also using Python and asked on the Python forum as well. Thanks.
Here is my loop, and th eif statement to catch if there is no "open" alt tag.
Here is my loop, and th eif statement to catch if there is no "open" alt tag.
- Code:
CSN = ['12275632444', '12275627859', '12275627856']
for CSNumber in CSN:
driver.find_element_by_id("fnsearchuc_temp2__ctl14_tbSimple").clear()
driver.find_element_by_id("fnsearchuc_temp2__ctl14_tbSimple").send_keys(CSNumber)
driver.find_element_by_css_selector("span[title="Find Now"]").click()
# need to check if no img open the go to next claim number then set errorNum = 1
if not driver.find_element_by_css_selector("img[alt="Open:"]"): break
time.sleep(1)
driver.find_element_by_css_selector("img[alt="Open:"]").click()
time.sleep(2)
#x and y axis is based on the position of the screen scrap browser not the save dialog box
self.save_click(570,540)
time.sleep(2)
- rsvore
- Posts : 4
Join date : 2012-11-08
using a try catch
Thu Nov 08, 2012 9:35 pm
I changed my code to this below and it's starting to work. but I get a long delay during the except.
- Code:
CSN = open('inputCSN.txt', 'r')
# set errorNum to 0 if 1 there was an problem
errorNum = 0
for CSNumber in CSN:
driver.find_element_by_id("fnsearchuc_temp2__ctl14_tbSimple").clear()
driver.find_element_by_id("fnsearchuc_temp2__ctl14_tbSimple").send_keys(CSNumber)
driver.find_element_by_css_selector("span[title="Find Now"]").click()
# need to check if no img open the go to next claim number then set errorNum = 1
# if not driver.find_element_by_css_selector("img[alt="Open:"]"): break
time.sleep(1)
try:
driver.find_element_by_css_selector("img[alt="Open:"]").click()
except:
outputCSN = open('outputCSN.txt', 'a')
outputCSN.write('There was an error with CSN:'+CSNumber)
time.sleep(2)
#x and y axis is based on the position of the screen scrap browser not the save dialog box
self.save_click(570,540)
time.sleep(2)
- rsvore
- Posts : 4
Join date : 2012-11-08
Re: Check for img alt and continue for loop
Thu Nov 08, 2012 10:03 pm
During the exception it takes 35 seconds before it moves on. not sure why.
Permissions in this forum:
You cannot reply to topics in this forum
|
|