0

Say i have a list , which consist of selenium commands like

browser = webdriver.Firefox()

lis = ['browser.find_element_by_id("gbqfba").click()' ,'browser.find_element_by_id("signup_btn_topPanel").click()']

tried to send the commands as,

for i in lis:

    driver.i

Since i is a string here, python is not accepting it. Any solutions for this??

0

2 Answers 2

1

you can use the exec command to run strings as python commands:

for i in lis:
   exec 'driver.' + i

should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

It may be more readable to make a list of dicts and use getattr()

For example:

cmd_dict = { 'method' : 'find_element_by_css_selector', 'args' : ('div.btn',) }
method_to_run = getattr( browser, cmd_dict['method'] )
method_to_run( *cmd_dict['args'] )

Comments

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.