1

I'm trying to give clicks on some elements that have the same id and name, after clicking on of those elements , the element disappears and then I want to click the next one. What I want to create is a loop to click on the elements and if there's no more elements with same id or name it should pass and continue the test, this is the element:

mark_complete = self.driver.find_element_by_xpath('//button[contains(.,"Mark complete")]') 

thanks in advance

1 Answer 1

1

I found the solution:

def mark_complete(self):
       while True:
             try:
               mark_complete = self.driver.find_element_by_xpath('//button[contains(.,"Mark complete")]')
               mark_complete.click()
             except NoSuchElementException:
               break
Sign up to request clarification or add additional context in comments.

2 Comments

this should work for a "show more" button that keeps loading more and more content, right?
Yes Anthony, just change the xpath for your element and that's all

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.