0

I have a problem with my test - adding a new query on a site. There are 2 existing queries already with id-0, id-1... You don't know how many queries will be added so I want to add a new query without giving the specific id number. I was trying to start with iterating but I don't know how to proceed with this code...

list_of_elements = wd.find_elements_by_css_selector("cssselector")
    for element in list_of_elements:
        wd.find_element_by_link_text("Add test").click()
        queries = wd.find_elements_by_css_selector('[id*="id_query-1-title"]')
        index = str(len(queries))
        wd.find_element_by_id('id_query-' + index + '-title').click()
        wd.find_element_by_id('id_query-' + index + '-title').clear()
        wd.find_element_by_id('id_query-' + index + '-title').send_keys("ABC")
15
  • So what is your problem/question? Commented Jan 24, 2017 at 19:58
  • I get a new query with id_query-2-title but what should i do to get a new query if there are more than exisitng 2 queries? I get/modify always a query with id_query-2-title... Commented Jan 24, 2017 at 20:02
  • Can you share URL of target page or at least HTML? Commented Jan 24, 2017 at 20:10
  • you are iterating over a list of elements, and then doing nothing with those elements. why? Commented Jan 24, 2017 at 20:11
  • 1
    @Storm, and what is len(queries)? Are you sure that it's more than 1? Maybe you need to use wd.find_elements_by_css_selector('[id*="id_query-"]')? However, without HTML it's hard to understand what you actually intend to do... Commented Jan 24, 2017 at 20:30

1 Answer 1

1

OK, I have a solution. Thank you for your help!

test = wd.find_elements_by_class_name('classname')
    test_count = len(test)
    test_string = str(test_count - 1)
    wd.find_element_by_id('id_query-' + test_string + '-title').click()
    wd.find_element_by_id('id_query-' + test_string + '-title').send_keys("ABC")
Sign up to request clarification or add additional context in comments.

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.