当前位置: 首页>>代码示例>>Python>>正文


Python Browser.is_element_present_by_name方法代码示例

本文整理汇总了Python中splinter.Browser.is_element_present_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.is_element_present_by_name方法的具体用法?Python Browser.is_element_present_by_name怎么用?Python Browser.is_element_present_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在splinter.Browser的用法示例。


在下文中一共展示了Browser.is_element_present_by_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: DakokuWorker

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_name [as 别名]
class DakokuWorker(object):
    def __init__(self, host, user, password, holidays, capture_dir=None):
        self.host = host
        self.user = user
        self.password = password
        self.holidays = holidays
        self.capture_dir = capture_dir
        self.browser = None

    def _is_same_day(self, t1, t2):
        return t1.strftime('%Y%m%d') == t2.strftime('%Y%m%d')

    def _is_holiday(self, t):
        for h in self.holidays:
            if self._is_same_day(t, h): return True
        return False

    def _login(self):
#        self.browser = Browser("phantomjs", user_agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36")
        self.browser = Browser("firefox")
        self.browser.visit(self.host)
        self.browser.fill('user_id', self.user)
        self.browser.fill('password', self.password)
        try:
            log.info("logging in: %s", self.browser.title.decode('utf-8'))
        except:
            log.info("logging in: %s", self.browser.title)

    def work_start(self):
        now_time = dt.datetime.now().replace(tzinfo=pytz.timezone('Asia/Tokyo'))
        try:
            if self._is_holiday(now_time):
                log.info("Today is holiday! Skipping...")
                return
            self._login()
            if self.browser.is_element_present_by_name("syussya", wait_time=5):
                self.browser.find_by_name("syussya").click()
            else:
                log.error("failed to load web page")
                return
            log.info(now_time.strftime("work started at %Y-%m-%d %H:%M:%S"))
            if self.capture_dir:
                capture_path = os.path.join(self.capture_dir, now_time.strftime('syussya_%Y-%m-%d-%H:%M:%S.jpg'))
                tmppath = self.browser.screenshot(suffix="jpg")
                log.info("captured: %s", tmppath)
                shutil.copyfile(tmppath, capture_path)
                log.info("copied to: %s", capture_path)
        except Exception as e:
            log.error("failed to start work: %s", str(e))
        finally:
            self.browser.quit()

    def work_end(self):
        now_time = dt.datetime.now().replace(tzinfo=pytz.timezone('Asia/Tokyo'))
        try:
            if self._is_holiday(now_time):
                log.info("Today is holiday! Skipping...")
                return
            self._login()
            if self.browser.is_element_present_by_name("taisya", wait_time=5):
                self.browser.find_by_name("taisya").click()
            else:
                log.error("failed to load web page")
                return
            log.info(now_time.strftime("work ended at %Y-%m-%d %H:%M:%S"))
            if self.capture_dir:
                capture_path = os.path.join(self.capture_dir, now_time.strftime('taisya_%Y-%m-%d-%H:%M:%S.jpg'))
                tmppath = self.browser.screenshot(suffix="jpg")
                log.info("captured: %s", tmppath)
                shutil.copyfile(tmppath, capture_path)
                log.info("copied to: %s", capture_path)
        except Exception as e:
            log.error('failed to end work: %s', str(e))
        finally:
            self.browser.quit()
开发者ID:furushchev,项目名称:dakoku,代码行数:77,代码来源:dakoku.py

示例2: UploadTestCase

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_name [as 别名]
class UploadTestCase(unittest.TestCase):

  def setUp(self):
    self.testbed = testbed.Testbed()
    self.testbed.activate()
    self.testbed.init_datastore_v3_stub()
    self.testbed.init_memcache_stub()
    self.browser = Browser('chrome')

  def tearDown(self):
    self.testbed.deactivate()

  def test_when_create_task_upload_file(self):
    #login
    self.browser.visit("http://127.0.0.1:8080/")
    self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
    self.browser.find_by_id("submit-login").first.click()
    self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")

    self.browser.visit("http://127.0.0.1:8080/tasks")

    self.browser.click_link_by_text('Create new task')

    self.browser.fill('title', 'title')
    self.browser.fill('text', 'text')

    self.browser.is_element_present_by_name('files[]', wait_time=10)

    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    #self.browser.attach_file('files[]', 'test/1.png')
    self.browser.find_by_css('.btn.btn-primary.start').first.click()


    self.assertEqual(1, len(self.browser.find_by_css('.template-download.fade.in')))
    self.assertEqual(4, len(self.browser.find_by_css('.template-download.fade.in td')))

  def test_when_create_task_upload_many_files(self):
    #login
    self.browser.visit("http://127.0.0.1:8080/")
    self.assertEqual(self.browser.find_by_tag("h3").first.text, "Not logged in")
    self.browser.find_by_id("submit-login").first.click()
    self.assertEqual(self.browser.find_link_by_text("Insurance").first.text, "Insurance")

    self.browser.visit("http://127.0.0.1:8080/tasks")

    self.browser.click_link_by_text('Create new task')

    self.browser.fill('title', 'title')
    self.browser.fill('text', 'text')

    self.browser.is_element_present_by_name('files[]')

    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))
    self.browser.attach_file('files[]', os.path.join(os.path.dirname(__file__),'1.png'))

    #self.browser.attach_file('files[]', 'test/1.png')
    self.browser.find_by_css('.btn.btn-primary.start').first.click()
    sleep(3)

    self.assertEqual(3, len(self.browser.find_by_css('.files tr.template-download')))
开发者ID:chybatronik,项目名称:task-manager-gae,代码行数:63,代码来源:test_upload_file.py

示例3: __init__

# 需要导入模块: from splinter import Browser [as 别名]
# 或者: from splinter.Browser import is_element_present_by_name [as 别名]
class Compass:

    def __init__(self, username='', password='', outdir=''):
        self._username = username
        self._password = password
        self._outdir = outdir

        self._browser = None
        self._record = None


    def quit(self):
        if self._browser:
            self._browser.quit()
            self._browser = None

    def loggin(self):
        prefs = {
            "browser.download.folderList": 2,
            "browser.download.manager.showWhenStarting": False,
            "browser.download.dir": self._outdir,
            "browser.helperApps.neverAsk.saveToDisk": "application/octet-stream,application/msexcel,application/csv"}

        self._browser = Browser('chrome') #, profile_preferences=prefs)

        self._browser.visit('https://compass.scouts.org.uk/login/User/Login')

        self._browser.fill('EM', self._username)
        self._browser.fill('PW', self._password)
        time.sleep(1)
        self._browser.find_by_text('Log in').first.click()

        # Look for the Role selection menu and select my Group Admin role.
        self._browser.is_element_present_by_name(
            'ctl00$UserTitleMenu$cboUCRoles',
            wait_time=30)
        self._browser.select('ctl00$UserTitleMenu$cboUCRoles', '1253644')
        time.sleep(1)

    def wait_then_click_xpath(self, xpath, wait_time=30, frame=None):
        frame = self._browser if frame is None else frame
        while True:
            try:
                if frame.is_element_present_by_xpath(xpath, wait_time=wait_time):
                    frame.find_by_xpath(xpath).click()
                    break
                else:
                    log.warning("Timeout expired waiting for {}".format(xpath))
                    time.sleep(1)
            except:
                log.warning("Caught exception: ", exc_info=True)

    def wait_then_click_text(self, text, wait_time=30, frame=None):
        frame = self._browser if frame is None else frame
        while True:
            if frame.is_text_present(text, wait_time=wait_time):
                frame.click_link_by_text(text)
                break
            else:
                log.warning("Timeout expired waiting for {}".format(text))

    def adult_training(self):
        self.home()

        # Navigate to training page a show all records.
        self.wait_then_click_text('Training')
        time.sleep(1)
        self.wait_then_click_text('Adult Training')
        time.sleep(1)
        self.wait_then_click_xpath('//*[@id="bn_p1_search"]')

    def home(self):
        # Click the logo to take us to the top
        self.wait_then_click_xpath('//*[@alt="Compass Logo"]')
        time.sleep(1)

    def search(self):
        self.home()

        # Click search button
        self.wait_then_click_xpath('//*[@id="mn_SB"]')
        time.sleep(1)

        # Click "Find Member(s)"
        self.wait_then_click_xpath('//*[@id="mn_MS"]')
        time.sleep(1)

        # Navigate to training page a show all records.
        with self._browser.get_iframe('popup_iframe') as i:
            self.wait_then_click_xpath('//*[@id="LBTN2"]', frame=i)
            time.sleep(1)
            self.wait_then_click_xpath('//*[@class="popup_footer_right_div"]/a', frame=i)
            time.sleep(1)

    def lookup_member(self, member_number):
        self.home()

        # Click search button
        self.wait_then_click_xpath('//*[@id="mn_SB"]')
        time.sleep(1)
#.........这里部分代码省略.........
开发者ID:hippysurfer,项目名称:scout-records,代码行数:103,代码来源:compass.py


注:本文中的splinter.Browser.is_element_present_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。