'How to make something true if xpath is visible on python using selenium

Is there a way to make something like this work?

while mining_first_button = browser.find_elements_by_xpath('/html/body/div/div[2]/div[4]/div[3]/div[1]/div/div/div/div[12]/button/div/span/svg'):
      mining_quest_in_progress = True

while mining_quest_done == True:

        mining_quest_done_not_collected_quest_click_2 = browser.find_element_by_xpath("/html/body/div/div[2]/div[4]/div[3]/div[1]/div/div/div/div[12]/button/div/span/svg")
        mining_quest_done_not_collected_quest_click_2.click()
        print("Hero is done")
        time.sleep(1)


Solution 1:[1]

Some workaround like this should work:

mining_first_button = browser.find_elements_by_xpath('/html/body/div/div[2]/div[4]/div[3]/div[1]/div/div/div/div[12]/button/div/span/svg')
if len(mining_first_button)>0:
      #... your code here ....
else:
    print("No such xpath exists")

You may use try/except too in lieu of if/else

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anand Gautam