gallly
gallly

Reputation: 1211

how to use a variable in selenium webdriver find element by xpath?

so I have a variable named folder which contains a string that I randomly generate. I want to use xpath to find this folder by name, and I am not sure how to put this into action

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

where variable contains the randomized text. With sql it would be like this (select * from table where value =(?)), [variable] ...or something similar

Upvotes: 6

Views: 9683

Answers (1)

alecxe
alecxe

Reputation: 474171

Try this:

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

Upvotes: 11

Related Questions