Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Selenium WebDriver Integration
Tue Nov 21, 2017 1:06 pm by azharuddin

» how to connect DB in selenium webriver
Fri Oct 06, 2017 4:09 pm by anbarasi

» How find any text in browser screen and click on it?
Thu Oct 05, 2017 2:02 pm by sandeepkommineni

» Selenium Webdriver
Tue Oct 03, 2017 1:35 pm by PiyushBiswas

» GRID setup tutorial.
Wed Sep 27, 2017 4:29 pm by johnyapp

» Drag & Drop Between Windows Using Selenium Driver
Wed Sep 27, 2017 2:10 pm by 26rondel

» Check if window is closed / verify input
Sat Sep 23, 2017 10:21 pm by brainstir

» How to work on pages with AJAX in selenium?
Mon Sep 18, 2017 6:08 pm by azharuddin

» pause test until user press a key like F2
Wed Aug 09, 2017 11:10 pm by djnforce

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