Python 如何在SeleniumWebDriver中使用变量通过xpath查找元素?

Python 如何在SeleniumWebDriver中使用变量通过xpath查找元素?,python,webdriver,Python,Webdriver,所以我有一个名为folder的变量,它包含我随机生成的字符串。我想使用xpath按名称查找此文件夹,但我不确定如何将其付诸实施 driver.find_element_by_xpath('//div[text()="variable"]') 其中变量包含随机文本。使用sql时,类似于从表中选择*,其中值=,[variable]…或类似的内容 driver.find_element_by_xpath('//div[text()="%s"]' % variable) 当然,这是python,简单

所以我有一个名为folder的变量,它包含我随机生成的字符串。我想使用xpath按名称查找此文件夹,但我不确定如何将其付诸实施

driver.find_element_by_xpath('//div[text()="variable"]')
其中变量包含随机文本。使用sql时,类似于从表中选择*,其中值=,[variable]…或类似的内容

driver.find_element_by_xpath('//div[text()="%s"]' % variable)

当然,这是python,简单比复杂好: