What is the solution to the #python# parameter passing problem?

dingjun_888 注册会员
2023-02-27 08:29

In your wrapper function key, the args argument appears to be a tuple containing the positioning method and the positioning expression for the positioning element. If you want to pass quoted variables when calling this function, you can do so as follows:

When calling senf_ctrl_key, change the value of the argument args to a string containing the positioning method and the expression, for example: args = "xpath,//span[ @class='soutu-hover-tip']".

In the senf_ctrl_key function, the argument args is resolved into positioning modes and expressions, which can be implemented using Python's string manipulation. For example, use the split() method to separate args into two comma-separated strings representing the positioning method and the expression:

def senf_ctrl_key(self, args, key):
    by, locator = args.split(',')
    self.find_element(by, locator).send_keys(Keys.CONTROL, key)

In the find_element function, pass the positioning mode and expression as parameters to Selenium's positioning methods:

def find_element(self, by, locator):
    element = self.driver.find_element(by, locator)
    return element

This way, you can pass the quoted variable when calling senf_ctrl_key. For example, if you want to type "test" in the input field, you can call it like this:

senf_ctrl_key(wps, "xpath,//input[ @id='kw']", "V")
wps.find_element("xpath,//input[ @id='kw']").send_keys("test")

drumying 注册会员
2023-02-27 08:29

Big brother, your argument self is unnecessary, key(c, 'V')

About the Author

Question Info

Publish Time
2023-02-27 08:29
Update Time
2023-02-27 08:29