1

I have a code for chrome driver to extract data

I have a code like this:

def click_all_options(path):
    try: 
        for option in browser.find_elements_by_xpath(path):
            option.click()
        return True
    except StaleElementReferenceException: 
        return False

select1 = '/html/body/form[2]/table/tbody/tr[1]/td[1]/select/option'
select2 = '/html/body/form[2]/table/tbody/tr[1]/td[2]/table/tbody/tr[1]/td[1]/select/option'

result = click_all_options(select1)
if not result:
        click_all_options(select2)

The problem is that this doesn't lead to a nested for loop. How can I tweak this to get a nested for loop?

Guy
  • 46,488
  • 10
  • 44
  • 88
  • You don't have nested for loop in the code you posted. And this is not how you should handle ` – Guy Mar 09 '20 at 06:00
  • @Guy this is not a select function. I could have named it A or B –  Mar 09 '20 at 06:07
  • No, this is a ` – Guy Mar 09 '20 at 06:09
  • @Guy I don't understand. It would be helpful if you post it as an answer. It will help others and I can upvote too –  Mar 09 '20 at 06:11
  • I don't really know what the original question is so I can't post an answer, and even if I posted it as an answer it will be exactly the same as in the answer I linked in my first comment (look at alecxe's top voted one, not the accepted one). Look at it or google "selenium python select option from select dropdown". – Guy Mar 09 '20 at 06:16
  • @guy but there is no select option here. –  Mar 09 '20 at 06:25
  • Yes there is, this is what you target in your xpath. – Guy Mar 09 '20 at 06:28
  • yes, but thats just a variable name –  Mar 09 '20 at 06:40
  • I'm talking about the xpath. In `select1` and `select2`. It targets ` – Guy Mar 09 '20 at 06:42
  • @Guy what is your suggestion? –  Mar 09 '20 at 18:44

0 Answers0