lundi 12 juin 2017

What is the proper structure to confirm if text exists on current URL and if not to continue checking the next URL?

I am working with Python and Selenium Webdriver in PyCharm. My goal is to create a test case that will check a web application page to see if there is a specific string of text. If the text is not on the current URL I would like the script to continue checking other URLs until the string of text is found.

If the string of text is found on a specific URL the test should pass, if it is found on other URLS it should fail.

My current code does not work as I am unsure of the proper structure but it looks like this:

# code to login to web app and navigate to desired URL
text = page.page_index100_error 

if self.driver.current_url.__contains__(text):
  print testrailFunctions.failed 
else:
   self.driver.get(self.base_url + "pageIndex=1"

if self.driver.current_url.__contains__(text):
  print testrailFunctions.failed 
else:
   self.driver.get(self.base_url + "pageIndex=2"

# and so on with the IF statements until pageIndex=100 is reached. 
# Whereupon the text should be found and the test should pass.

Any advice on changes I should make?

Thank you.

Aucun commentaire:

Enregistrer un commentaire