Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Regarding Alert Interface
Fri Feb 24, 2017 2:00 pm by karthikeyakumar

» Geting issues in identifying the elsements in webdriver
Fri Feb 17, 2017 4:41 pm by janbaskt

» WebDriver - why not to use a singlton for it?
Fri Feb 17, 2017 4:40 pm by janbaskt

» WebDriver session when using testng annotation to invoke driver instance
Fri Feb 17, 2017 4:39 pm by janbaskt

» Selenium fails to launch Chrome
Fri Feb 17, 2017 4:39 pm by janbaskt

» why do i get this error
Fri Feb 17, 2017 4:38 pm by janbaskt

» Selenium Tutorial
Thu Feb 16, 2017 5:21 pm by Rahul

» When to use Selenium IDE, RC and WebDriver
Mon Feb 13, 2017 2:35 pm by azharuddin

» How to integrate selenium with ZAPI-Zephyr
Sat Feb 11, 2017 2:25 am by gseera002c

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


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