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


Python WebDriver.execute_script方法代码示例

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

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

示例1: BaseLiveServerTestCase

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
class BaseLiveServerTestCase(LiveServerTestCase):
    def setUp(self):
        get_or_create_test_admin()
        self.browser = WebDriver()
        self.do_admin_login('test', 'test')

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

    def do_admin_login(self, username, password):
        self.browser.get('%s%s' % (self.live_server_url, '/admin/'))
        username_input = self.browser.find_element_by_name("username")
        username_input.send_keys(username)
        password_input = self.browser.find_element_by_name("password")
        password_input.send_keys(password)
        self.browser.find_element_by_xpath('//input[@value="Log in"]').click()

    def new_window(self, name='other'):
        self.browser.execute_script('window.open("/admin/", "'+ name +'")')
        self.browser.switch_to_window(self.browser.window_handles[1])
        while self.warning_element() is False:
            time.sleep(0.1)
        self.browser.switch_to_window(self.browser.window_handles[0])

    def press_space(self):
        a = ActionChains(self.browser)
        a.key_down(Keys.SPACE)
        a.perform()

    def wait_for_pages_loaded(self):
        for win in self.browser.window_handles:
            while self.warning_element() is False:
                time.sleep(0.1)
开发者ID:comandrei,项目名称:django-session-security,代码行数:35,代码来源:base.py


示例2: StickToTopTest

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
class StickToTopTest(LiveServerTestCase):

    def setUp(self):
        self.browser = WebDriver()
        self.browser.implicitly_wait(3)
        self.n1 = Node.objects.create(
            title='TestNodeOne',
            description='The first test node'
        )
        self.u1 = User.objects.create_user(
            username='test1', email='[email protected]', password='111'
        )
        self.super_user = User.objects.create_user(
            username='super', email='[email protected]', password='123'
        )
        self.super_user.is_superuser = True
        self.super_user.is_staff = True
        self.super_user.save()
        # Create 99 topics
        for i in range(1, 100):
            setattr(
                self,
                't%s' % i,
                Topic.objects.create(
                    title='Test Topic %s' % i,
                    user=self.u1,
                    content_raw='This is test topic __%s__' % i,
                    node=self.n1
                )
            )

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

    def test_stick_to_top_admin(self):
        self.browser.get(self.live_server_url + reverse("niji:index"))
        login(self.browser, 'super', '123')
        self.assertIn("Log out", self.browser.page_source)

        lucky_topic1 = getattr(self, 't%s' % random.randint(1, 50))

        self.browser.get(self.live_server_url+reverse('niji:topic', kwargs={"pk": lucky_topic1.pk}))
        self.browser.find_element_by_class_name('move-topic-up').click()
        up_level = WebDriverWait(
            self.browser, 10
        ).until(
            expected_conditions.presence_of_element_located(
                (By.NAME, 'move-topic-up-level')
            )
        )
        up_level = Select(up_level)
        up_level.select_by_visible_text('1')
        time.sleep(1)
        self.browser.execute_script("$('.modal-confirm').click()")
        self.browser.get(self.live_server_url+reverse('niji:index'))
        first_topic_title = self.browser.find_elements_by_class_name('entry-link')[0].text

        self.assertEqual(first_topic_title, lucky_topic1.title)
开发者ID:ericls,项目名称:niji,代码行数:60,代码来源:tests.py


示例3: LiveServerTest

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
class LiveServerTest(object):
    fixtures = ['rules.json']

    DOWNLOAD_DIRECTORY = '/tmp/work/downloads'


    ## List all ajax enabled pages that have initialization code and must wait
    AJAX_WAIT = ['mock_galaxy_factory', 'view_job']
    SUMMARY_INDEX = str(len(MODULE_INDICES)+1)
    OUTPUT_FORMATS = [
        {'value':'csv', 'text':'CSV (Text)', 'extension':'csv'},
        {'value':'hdf5', 'text':'HDF5', 'extension':'hdf5'},
        {'value': 'fits', 'text': 'FITS', 'extension': 'fits'},
        {'value': 'votable', 'text': 'VOTable', 'extension': 'xml'}
    ]

    def wait(self, secs=1):
        time.sleep(secs * 1.0)

    def setUp(self):

        from selenium.webdriver.firefox.webdriver import FirefoxProfile
        fp = FirefoxProfile()
        fp.set_preference("browser.download.folderList", 2)
        fp.set_preference("browser.download.dir", self.DOWNLOAD_DIRECTORY)
        fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/html, application/zip, text/plain, application/force-download, application/x-tar")
        
        self.selenium = WebDriver(firefox_profile=fp)
        self.selenium.implicitly_wait(1) # wait one second before failing to find

        # create the download dir
        if not os.path.exists(self.DOWNLOAD_DIRECTORY):
            os.makedirs(self.DOWNLOAD_DIRECTORY)

    def tearDown(self):
        self.selenium.quit()
        # remove the download dir
        for root, dirs, files in os.walk(self.DOWNLOAD_DIRECTORY, topdown=False):
            for name in files:
                os.remove(os.path.join(root, name))
            for name in dirs:
                os.rmdir(os.path.join(root, name))

    def lc_id(self, bare_field):
        return '#id_light_cone-%s' % bare_field

    def lc_2select(self, bare_field):
        return 'id_light_cone-output_properties_%s' % bare_field

    def rf_id(self, bare_field):
        return '#id_record_filter-%s' % bare_field

    def sed(self, bare_field):
        return 'id_sed-%s' % bare_field

    def mi_id(self, bare_field):
        return 'id_mock_image-%s' % bare_field

    def sed_id(self, bare_field):
        return '#%s' % self.sed(bare_field)

    def sed_2select(self, bare_field):
        return 'id_sed-band_pass_filters_%s' % bare_field

    def job_select(self, bare_field):
        return 'id-job_%s' % bare_field

    def job_id(self, bare_field):
        return '#%s' % self.job_select(bare_field)

    def get_parent_element(self, element):
        return self.selenium.execute_script('return arguments[0].parentNode;', element)

    def get_element_css_classes(self, element):
        list = []
        found = element.get_attribute('class')
        if found is not None: list = found.split()
        return list

    def get_closest_by_class(self, element, css_class):
        while css_class not in self.get_element_css_classes(element):
            element = self.get_parent_element(element)
        return element

    def get_summary_selector(self, form_name, field_name):
        return 'div.summary_%s .%s' % (form_name, field_name)

    def get_summary_field(self, form_name, field_name):
        summary_selector = self.get_summary_selector(form_name, field_name)
        return self.selenium.find_element_by_css_selector(summary_selector)

    def get_summary_field_text(self, form_name, field_name):
        return self.get_summary_field(form_name, field_name).text

    def get_info_field(self, section, field):
        elem = self.selenium.find_element_by_css_selector("div.%(section)s-info .%(field)s" % {'section': section, 'field': field})
        return elem.text

    def find_element_by_css_selector(self, selector):
        retries = 3
#.........这里部分代码省略.........
开发者ID:IntersectAustralia,项目名称:asvo-tao,代码行数:103,代码来源:ithelper.py


示例4: WebDriverWait

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
    driver.find_element_by_xpath("//ul[@class='ari-caused-spacer-expand']/li[3]").click()
    driver.find_element_by_id("arisearch_txtSearch").click()
    driver.find_element_by_id("arisearch_txtSearch").clear()
    driver.find_element_by_id("arisearch_txtSearch").send_keys("209617GS")
    driver.find_element_by_id("arisearch_btnLookup").click()

    # The following div classes get in the way of our user click as seen in errors
    # and we must change the css with javascript to allow the button click without a sleep statement
    # <div class="blockUI blockOverlay" ... wait; position: absolute;"></div>

    try:
        hideElement = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "blockUI")))
    except Exception, e:
        print("BlockUI not found")
    try:
        driver.execute_script("document.getElementsByClassName('blockUI blockOverlay')[0].style.height = '1px';")
    except Exception, e:
        print('blocking class not there')

    # The curtain <div> also prevents us from click so that is handled by a wait statement
    check = WebDriverWait(driver, 10).until_not(EC.presence_of_element_located((By.ID, "curtain")))

    # Add item 209617GS to cart
    WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "input.ariPartListAddToCart.ariImageOverride")))
    element = driver.find_element_by_xpath("//input[@id='aripartsSearch_btnCart0']")
    WebDriverWait(driver, 10).until_not(EC.presence_of_element_located((By.ID, "curtain")))
    driver.find_element_by_id('aripartsSearch_btnCart0').click()

    # Click My Cart(1) to load Shopping cart page
    wait = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.LINK_TEXT, "My Cart(1)")))
开发者ID:ichbinpete,项目名称:Briggs-Synth-AddToCart,代码行数:33,代码来源:FireFox-Add+toCart.py


示例5: ScriptTestCase

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
class ScriptTestCase(LiveServerTestCase):
    def setUp(self):
        self.browser = WebDriver()
        self.do_admin_login('test', 'test')

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

    def do_admin_login(self, username, password):
        self.browser.get('%s%s' % (self.live_server_url, '/admin/'))
        username_input = self.browser.find_element_by_name("username")
        username_input.send_keys(username)
        password_input = self.browser.find_element_by_name("password")
        password_input.send_keys(password)
        self.browser.find_element_by_xpath('//input[@value="Log in"]').click()

    def new_window(self, name='other'):
        self.browser.execute_script('window.open("/admin/", "'+ name +'")')
        self.browser.switch_to_window(self.browser.window_handles[1])
        while self.warning_element() is False:
            time.sleep(0.1)
        self.browser.switch_to_window(self.browser.window_handles[0])

    def press_space(self):
        a = ActionChains(self.browser)
        a.key_down(Keys.SPACE)
        a.perform()

    def warning_element(self):
        try:
            return self.browser.find_elements_by_css_selector(
                '#session_security_warning')[0]
        except IndexError:
            return False

    def wait_for_pages_loaded(self):
        for win in self.browser.window_handles:
            while self.warning_element() is False:
                time.sleep(0.1)

    def deadline_passed(self, now, deadline):
        return (datetime.now() - now).seconds > deadline

    def assertWarningShows(self, max_seconds):
        now = datetime.now()

        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)

            while self.warning_element() is False:
                time.sleep(0.1)

                if self.deadline_passed(now, max_seconds):
                    self.fail('Warning did not make it into DOM')

        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)

            while self.warning_element().is_displayed() is False:
                time.sleep(0.1)

                if self.deadline_passed(now, max_seconds):
                    self.fail('Warning did not make it into DOM')

    def assertWarningHides(self, max_seconds):
        now = datetime.now()

        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)

            while self.warning_element().is_displayed() is not False:
                time.sleep(0.1)

                if self.deadline_passed(now, max_seconds):
                    self.fail('Warning did not hide')

    def assertExpires(self, max_seconds):
        now = datetime.now()

        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)

            while self.warning_element() is not False:
                time.sleep(0.1)

                if self.deadline_passed(now, max_seconds):
                    self.fail('Warning did not make it out of DOM')

    def assertWarningShown(self):
        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)
            self.assertTrue(self.warning_element().is_displayed())

    def assertWarningHidden(self):
        for win in self.browser.window_handles:
            self.browser.switch_to_window(win)
            self.assertFalse(self.warning_element().is_displayed())

    def assertWarningNotInPage(self):
        for win in self.browser.window_handles:
#.........这里部分代码省略.........
开发者ID:yscumc,项目名称:django-session-security,代码行数:103,代码来源:script.py


示例6: wait_until_ready

# 需要导入模块: from selenium.webdriver.firefox.webdriver import WebDriver [as 别名]
# 或者: from selenium.webdriver.firefox.webdriver.WebDriver import execute_script [as 别名]
 def wait_until_ready(self):
     self.wait.until(lambda driver: WebDriver.execute_script(
         driver, 'return document.readyState;') == 'complete')
开发者ID:pombredanne,项目名称:dezede,代码行数:5,代码来源:simulation.py



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