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


Python Firefox.find_elements_by_tag_name方法代码示例

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


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

示例1: NewTrainingData

# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import find_elements_by_tag_name [as 别名]
class NewTrainingData(LiveServerTestCase) :
    def setUp(self) :
        # TODO setup lists with test data here, and make the 2 methods user_sees and check_entered accept these lists
        self.browser = Firefox()
        self.browser.implicitly_wait(3)

    def tearDown(self) :
        self.browser.quit()

    def user_sees_inputfields_and_enters_data(self, distance, executed_time, in_zone, average_heart_rate) :
        # user sees 4 edit boxes to enter distance, executed time, in zone and average HR 
        distance_editbox = self.browser.find_element_by_name('distance')
        self.assertIsNotNone(distance_editbox)
        
        executed_time_editbox = self.browser.find_element_by_name('executed_time')
        self.assertIsNotNone(executed_time_editbox)

        in_zone_editbox = self.browser.find_element_by_name('in_zone')
        self.assertIsNotNone(in_zone_editbox)

        average_heart_rate_editbox = self.browser.find_element_by_name('average_heart_rate')
        self.assertIsNotNone(average_heart_rate_editbox)

        # TODO: user sees km, bpm, .... next to the edit boxes

        # user sees a submit button with the text 'submit' on it
        submit_button = self.browser.find_element_by_id('submit_button')
        self.assertEqual(submit_button.get_attribute('value'), 'submit')

        # user enters data in the 4 fields an presses submit
        # TODO : user sees he gets redirected to the same home url
        distance_editbox.send_keys(distance)
        executed_time_editbox.send_keys(executed_time)
        in_zone_editbox.send_keys(in_zone)
        average_heart_rate_editbox.send_keys(average_heart_rate)
        submit_button.submit()
        
       
    def check_entered_data_on_screen(self, data) :
        # user sees a table and an entry in a table on the page with the entered data 
        try :
            table_rows = self.browser.find_elements_by_tag_name('tr')
        except StaleElementReferenceException :
            # wait for all the elements to be attached to the DOM (stale exception selenium)
            self.browser.implicitly_wait(3)
            table_rows = self.browser.find_elements_by_tag_name('tr')

        # user checks if the number of rows entered equals the number of rows displayed in the table
        self.assertEqual(len(table_rows), len(data), 'not all data records are in the DB')
        for table_row in table_rows :
            self.assertIn(table_row.text, data, 'runners record wrong data or not in DB')

    def test_enter_training_data(self) :
        # user gets the url
        self.browser.get(self.live_server_url)
        # user enters a first set of data and checks if the data is receptioned by the system
        self.user_sees_inputfields_and_enters_data('9', '00:46:48', '00:38:42', '162')
        # user sees the row in the table on the page matching the data entered
        self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162'])
        
        # user enters a second set of data checks if the data is receptioned by the system
        self.user_sees_inputfields_and_enters_data('14.182', '01:08:53', '00:52:23', '159')
        # user sees both rows in the table on the page matching the data from the second training session
        self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162', '14.182 1:08:53 0:52:23 159'])
        
        # user closes the browser and reopens, to see his previously entered data
        self.tearDown()
        self.setUp()
        # user gets the url
        self.browser.get(self.live_server_url)
        self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162', '14.182 1:08:53 0:52:23 159'])

    def test_web_page_is_loaded(self) :
        # user gets the url
        self.browser.get(self.live_server_url)
        # user sees the title in the browser window
        self.assertIn('Runners Log', self.browser.title)
开发者ID:stevenengelen,项目名称:runnerslog,代码行数:79,代码来源:tests.py


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