Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Check for img alt and continue for loop

View previous topic View next topic Go down

Check for img alt and continue for loop

Post by rsvore on 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.
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

Back to top Go down

using a try catch

Post by rsvore on 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

Back to top Go down

Re: Check for img alt and continue for loop

Post by rsvore on Thu Nov 08, 2012 10:03 pm

During the exception it takes 35 seconds before it moves on. not sure why.

rsvore

Posts : 4
Join date : 2012-11-08

Back to top Go down

Re: Check for img alt and continue for loop

Post by Sponsored content Today at 1:03 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum