【问题标题】:TypeError: must be str, not tuple. Variable as a string in an Array [closed]TypeError:必须是 str,而不是 tuple。变量作为数组中的字符串[关闭]
【发布时间】:2018-04-21 16:44:38
【问题描述】:

这是我的代码,我不断收到 TypeError: must be str, not tuple

variable = ["Variable1", "Variable2"]

def command(self, *arg):
    numparm = len(arg)
    for i in range (0,numparm):
        self.driver.find_element_by_xpath(".//div[text()='"+ arg[i] +"']")

command(variable)

【问题讨论】:

    标签: python python-2.7 python-3.x selenium selenium-webdriver


    【解决方案1】:

    *args 表示参数的解包列表,所以元组应该被解包:command(*variable) 或者如果你想按原样传递它,你可以定义command(args) 然后调用command(variable)。 代码中的 self 参数是一个错字。

    【讨论】:

    • 完美,成功了。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-11
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-06
    • 2015-08-04
    相关资源
    最近更新 更多