Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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
add comment

1 Answer

up vote 0 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
add comment

Your Answer

 
discard

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.