3

To assert the page title, I do not want to do a hard check but rather a soft one, something like a string pattern match on the page title. For this, here is an excerpt of my code which unfortunately is not working:

wait = WebDriverWait(self.driver, 15)
wait.until(lambda driver:self.driver.title.lower().startswith('Checkout'))
self.assertIn("Checkout", self.driver.title)

This is the exact title of the page: Checkout - HarXYZ

Can someone please point out where I am making a mistake? Is there any other way of asserting the page title through string pattern match?

1 Answer 1

5

self.driver.title.lower().startswith('Checkout') will always return False, because Checkout contain uppercase letter C.

wait.until(lambda driver:self.driver.title.lower().startswith('checkout'))
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks falsetru. It worked! Such a silly mistake!!! I have just one more doubt. Just like startswith(), do we have something like contains() or some other method for string match comparison?
@Praveen, There is in operator. needle in haystack.

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.