如何在 Selenium Webdriver 2 Python 中获取当前 URL? [英] How do I get current URL in Selenium Webdriver 2 Python?

查看:21
本文介绍了如何在 Selenium Webdriver 2 Python 中获取当前 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Selenium 中进行一系列导航后获取当前 url.我知道 ruby​​ 有一个名为 getLocation 的命令,但我找不到 Python 的语法.

I'm trying to get the current url after a series of navigations in Selenium. I know there's a command called getLocation for ruby, but I can't find the syntax for Python.

推荐答案

为 Python 2 使用 current_url 元素:

Use current_url element for Python 2:

print browser.current_url

对于 Python 3 及更高版本的 selenium:

For Python 3 and later versions of selenium:

print(driver.current_url)

这篇关于如何在 Selenium Webdriver 2 Python 中获取当前 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆