Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am doing a selenium automation where I want to pass the variable into the xpath and select the element.

The xpath which I am trying looks like: browser.find_element_by_xpath("//span[contains(.,'SEM W880 Black')]")

I would like to pass the text ,SEM W880 Black as a variable to the xpath. How can I do it using python 3. Can somebody help me.

share|improve this question
up vote 1 down vote accepted

At first glance, this appears to be a Python question rather than a QA question. The answer to the Python question is something like,

x = 'SEM W880 Black'
browser.find_element_by_xpath("//span[contains(.,'" + x + "')]")

If I misunderstood you, please update the question.

share|improve this answer
This is neat answer,I have not thought we can write in python. I thought there could be a function in the selenium where I can pass the variable as a parameter to the function. – Ranadheer Dec 10 '13 at 9:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.