コード例 #1
0
 def refrun(self, rownum, handle, dr, element, param):
     result = ''
     rbr = browser(dr, param, element)
     if hasattr(rbr, handle):
         try:
             func = getattr(rbr, handle)
             result = func()
         except TimeoutError as e:
             dr.execute_script('windows.stop()')
             logging.error('行号:' + str(rownum) +
                           'TimeoutError:windows.stop ' + repr(e))
         except NoSuchElementException as ne:
             timeout = 0
             while (('NoSuchElementException' in repr(ne))) & (
                     timeout < int(overalldict.get('timeout'))):
                 time.sleep(0.5)
                 try:
                     func = getattr(rbr, handle)
                     result = func()
                 except NoSuchElementException:
                     timeout = timeout + 0.5
                     logging.info('Auto Wait:' + str(timeout))
         rbr = browser(dr, None, None)
         func = getattr(rbr, 'switchtowindow_closeOthers')
         func()
         if result is None:
             result = ''
     return result
コード例 #2
0
from selenium import webdriver
from time import sleep
from base import Base, browser
driver = browser()
driver.get('http://127.0.0.1:81/zentao/user-login.html')
zentao = Base(driver)
loc1 = ('xpath', '//*[@id="login-form"]/form/table/tbody/tr[4]/td/a')
r1 = zentao.is_text_in_element(loc1, '忘记密码')
print(r1)
r2 = zentao.is_text_in_element(loc1, '3333')
print(r2)
driver.quit()