首页 > 解决方案 > 如何在 Python 中将 int 与字符串连接起来?

问题描述

我想将 for 循环的 i 与 xpath 连接,但它给了我这个错误“TypeError: can only concatenate str (not "int") to str”。我该如何解决这个问题?

    guardaremail = 'asd@asd'

    teste = self.driver.find_element_by_xpath("//*[text()='" + guardaremail + "']")
    tabela = self.driver.find_elements_by_xpath("/html/body/div[1]/div/table/tbody/tr")

    for i in range(1, len(tabela), 1):

        #verifica if tr = email
        emailteste = self.driver.find_element_by_xpath("/html/body/div[1]/div/table/tbody/tr[" + i + "]/td[2]")
        botaoteste = self.driver.find_element_by_xpath("/html/body/div[1]/div/table/tbody/tr[" + i + "]/button[1]")

        #carrega no tr com id = "ui positive button"
        if emailteste == teste:
            botaoteste.click()

标签: python

解决方案


采用"tr"+str(i)+"/td


推荐阅读