[英]How to use driver.current_url on a new tab opened by .click() on Selenium for Python
[英]How to print a log based on a driver current URL in Python
目前正在从事一个小项目以掌握自动化的窍门,并想知道如何在 url 重定向到某个页面后打印显示登录状态的 go
if a is "https://pepsi.fooji.com/?#choose-address"
print(f"[{datetime.now()}] - Logged in!")
https://www.selenium.dev/selenium/docs/api/py/api.html
if driver.current_url is "https://pepsi.fooji.com/?#choose-address"
print(f"[{datetime.now()}] - Logged in!")
参考 python 类,如果你参考 webdriver 远程 class 你可以有一个内置的 current_url 属性,它将给出页面的当前 url
如果两个变量指向同一个 object, is
将返回True
。 如果变量引用的对象相等,则 as ==
将返回True
。
作为一种解决方案,您可以在通过driver.current_url
返回的字符串中验证字符串https://pepsi.fooji.com/?#choose-address
,如下所示:
if "https://pepsi.fooji.com/?#choose-address" in driver.current_url:
print(f"[{datetime.now()}] - Logged in!")
一种最佳方法验证通过driver.current_url
返回的字符串中的部分字符串choose-address
,如下所示:
if "choose-address" in driver.current_url:
print(f"[{datetime.now()}] - Logged in!")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.