使用“+变量名+”传入变量 comment_num = self.find(self._comment_num).text xpath = "//android.widget.TextView[@text='"+comment_num+"']/../../../../.." self.driver.find_element_by_xpath(xpath).click()