Python selenium2 dynamic debugging

Source: Internet
Author: User

#coding =utf-8
‘‘‘
Created on 2017-9-9

@author: Ceshi from https://testerhome.com/topics/9897
‘‘‘

# rpcserver.py
Import Pickle
From Selenium.webdriver.chrome.webdriver import Webdriver
From multiprocessing.connection import Listener
From threading Import Thread

Dr = Webdriver (executable_path= "D:\\python27\\chromedriver")


def rpc_server (Handler, address, Authkey):
Sock = Listener (address, Authkey=authkey)
While True:
Client = Sock.accept ()
t = Thread (target=handler.handle_connection, args= (client,))
T.daemon = True
T.start ()


Class Rpchandler (object):
def __init__ (self):
# RPC Functions Map
Self._functions = {}

def register_function (Self, func):
SELF._FUNCTIONS[FUNC.__NAME__] = Func

def handle_connection (self, Connection):
Try
While True:
#接收到一条消息, using Pickle Protocol encoding
Func_name, args, Kwargs = Pickle.loads (Connection.recv ())
# RPC calls the function and returns the result
Try
r = Self._functions[func_name] (*args, **kwargs)
Print (Type (r))
Connection.send (Pickle.dumps (R))
Except Exception as E:
Connection.send (Pickle.dumps (e))
Except Eoferror:
Pass


if __name__ = = ' __main__ ':
# Write a few test methods
def add ():
Reload (rpcclient)
Rpcclient.get (DR)
# Create a new instance of the handler class and register the Add method with the handler
Import Rpcclient
From IMP import reload
Rpc_handler = Rpchandler ()

Rpc_handler.register_function (ADD)


Rpc_server (Rpc_handler, (' 192.168.3.19 ', 17001), authkey=b ' Tab_space ')

==========================

#coding =utf-8
‘‘‘
Created on 2017-9-9

@author: Ceshi
‘‘‘

#rpcclient. py
Import Pickle


Class RpcProxy (object):
def __init__ (self, Connection):
Self._connection = Connection

def __getattr__ (self, name):
# by name, get a function
def do_rpc (*args, **kwargs):
Self._connection.send (Pickle.dumps ((name, args, Kwargs))
result = Pickle.loads (Self._connection.recv ())
If isinstance (result, Exception):
Raise result
return result

Return DO_RPC


def get (DR):
#dr. Get ("https://www.baidu.com")
Dr.get (' https://testerhome.com/topics/9897 ')
# Dr.get ("https://www.baidu.com")
# dr.find_element_by_id ("kw"). Send_keys ("Selenium")
# dr.find_element_by_id ("su"). Click ()


# Remote Connection and call
if __name__ = = ' __main__ ':
From multiprocessing.connection import Client

rpc_client = Client ((' 192.168.3.19 ', 17001), authkey=b ' Tab_space ')
Proxy = RpcProxy (rpc_client)
b = Proxy.add ()

Python selenium2 dynamic debugging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.