0

I am using Selenium 2 with Webdriver. I would like to pass in my desired environment as part of a set of test data. My code looks like this:

    capability = webdriver.DesiredCapabilities.FIREFOX

And works correctly. But I would like to pass the "FIREFOX" in from a variable, kind of like this:

    TestParameters['Environment']="FIREFOX"
    capability = webdriver.DesiredCapabilities.TestParameters['Environment']

But I get this error

AttributeError: type object 'DesiredCapabilities' has no attribute 'TestParameters'

What can I do to evaluate the variable contents as a method name?

2

1 Answer 1

1

Your code tries to access the attribute by the variable name instead of the variable value:

capability = webdriver.DesiredCapabilities.TestParameters['Environment']

As the error message says, this evaluates the TestParameters attribute of webdriver.DesiredCapabilites. Which it doesn't have.

What you want is to evaluate the attribute whose name is the value of TestParameters['Environment']:

capabilityAttributeName = TestParameters['Environment']
capability = getattr(webdriver.DesiredCapabilities, capabilityAttributeName)
Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I needed. I knew there had to be some simple bit of special sauce to make that work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.