码迷,mamicode.com
首页 > 编程语言 > 详细

python中执行js

时间:2017-12-13 14:23:59      阅读:820      评论:0      收藏:0      [点我收藏+]

标签:oal   name   body   lib   int   java   encoding   javascrip   release   

import execjs  
#执行本地的js  
  
def get_js():  
    # f = open("D:/WorkSpace/MyWorkSpace/jsdemo/js/des_rsa.js",‘r‘,encoding=‘UTF-8‘)  
    f = open("./js/des_rsa.js", r, encoding=UTF-8)  
    line = f.readline()  
    htmlstr = ‘‘  
    while line:  
        htmlstr = htmlstr + line  
        line = f.readline()  
    return htmlstr  
  
jsstr = get_js()  
ctx = execjs.compile(jsstr)  
print(ctx.call(enString,123456))  
class erp_canvas_driver( browserDriver):

    __inject_js_files__ = []

    def __init__(self):
        browserDriver.__init__(self)

        self.inject_js_files = [
            os.path.join(self.rootPath, lib/erp/javascripts/ERPOAL.js),
            os.path.join(self.rootPath, lib/erp/javascripts/ERPActors.js),
            os.path.join(self.rootPath, lib/erp/javascripts/browser_utils.js)
        ]

    def openPage(self, url=/ERP):
        if browserDriver.openPage(self, url):
            self.__initHelper__()

    def __injectJSCode__(self, path):
        js_lines = []
        file = open(os.path.abspath(path))
        for line in file:
            js_lines.append(line)

        self.browser.execute_script(\n.join(js_lines))

    def __initHelper__(self):
        for path in self.inject_js_files:
            self.__injectJSCode__(path)

        time.sleep(1)

    def navigateByButton(self, button_name):
        self.clickERPButton(button_name)
        time.sleep(5)
        try:
            WebDriverWait(self.browser, 10).until(
                EC.presence_of_element_located((By.ID, "obj1"))
            )
        finally:
            self.__initHelper__()

    def clickERPButton(self, name):
        code = mouseClick("{0}").format(name)
        self.browser.execute_script(code)

    def pressERPButton(self, name):
        code = mousePress("{0}").format(name)
        self.browser.execute_script(code)

    def releaseERPButton(self, name):
        code = mouseRelease("{0}").format(name)
        self.browser.execute_script(code)

    def waitDisplayUpdate(self, name, property, expect_value, timeout=20):
        n = min(int(timeout / 0.2), 50)
        for i in range(n):
            value = self.browser.execute_script(return ERPGetElementProperty("{0}", "{1}").format(name, property))
            if value == expect_value:
                return True
            time.sleep(0.2)
        return False

    def getElementProperty(self, name, property):
        return self.browser.execute_script(return ERPGetElementProperty("{0}", "{1}").format(name, property))

    def setElementProperty(self, name, property, value, isDigit=False):
        if isDigit:
            self.browser.execute_script(ERPSetElementProperty("{0}", "{1}", {2});.format(name, property, value))
        else:
            self.browser.execute_script(ERPSetElementProperty("{0}", "{1}", "{2}");.format(name, property, value))

 

python中执行js

标签:oal   name   body   lib   int   java   encoding   javascrip   release   

原文地址:http://www.cnblogs.com/jinzhuduoduo/p/8032052.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!