0

Currently working on a small project to get the hang of automation and was wondering how to go about printing a status showing logged in once the url redirects to a certain page



if a is "https://pepsi.fooji.com/?#choose-address"
    print(f"[{datetime.now()}] - Logged in!")
Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
Daniel
  • 1

2 Answers2

0

https://www.selenium.dev/selenium/docs/api/py/api.html

https://www.selenium.dev/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=current_url#selenium.webdriver.remote.webdriver.WebDriver.current_url

if driver.current_url is "https://pepsi.fooji.com/?#choose-address"
    print(f"[{datetime.now()}] - Logged in!")

Refer the python classes ,if you refer webdriver remote class you can is there is an inbuild current_url property that will give the current url of the page

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • I'm still confused so what should I do? For example I need to check the status of the entry. My code is as follows if "https://pepsi.fooji.com/?#unlucky" in driver.current_url: print(f"[{datetime.now()}] - Non winner, retrying entry") if "https://pepsi.fooji.com/?#winner" in driver.current_url: print(f"[{datetime.now()}] - Winner!, check your email.") It's not printing the current status though. – Daniel Feb 06 '21 at 03:15
0

is will return True if two variables point to the same object. Where as == will return True if the objects referred to by the variables are equal.

You can find a detailed relevan discussion in Is there a difference between "==" and "is"?


Solution

As a solution you can validate the string https://pepsi.fooji.com/?#choose-address with in the string returned through driver.current_url as follows:

if "https://pepsi.fooji.com/?#choose-address" in driver.current_url:
    print(f"[{datetime.now()}] - Logged in!")
    

A optimal approach validate the partial string choose-address with in the string returned through driver.current_url as follows:

if "choose-address" in driver.current_url:
    print(f"[{datetime.now()}] - Logged in!")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • @Daniel Checkout the updated answer and let me know the status. – undetected Selenium Feb 06 '21 at 00:08
  • Got it but for some reason when I am completing the giveaway in the browser the current URL is matching the code I have currently. ```if 'https://pepsi.fooji.com/?#unlucky' in driver.current_url: rint(f"[{datetime.now()}] - Non winner, retrying...")``` – Daniel Feb 06 '21 at 00:17
  • It's not printing the current status – Daniel Feb 06 '21 at 00:17
  • @Daniel _`Non winner, retrying...`_ sounds like a different issue all together. Can you raise a new question as per your new requirement? Stackoverflow contributors will be happy to help you out. – undetected Selenium Feb 06 '21 at 07:22