Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get current URL in Selenium Webdriver 2 Python?

People also ask

How do I get the current URL in Python?

You can get the current url by doing path_info = request. META. get('PATH_INFO') http_host = request.

How do you get the current page URL in Selenium?

We can obtain the URL of the current page with Selenium webdriver. This is achieved with the help of getCurrentUrl() method. It fetches the URL of the opened application. This method accepts no parameters and strings the URL in the form of String.

How do you select a link in Selenium Python?

We can click on a link using Selenium webdriver in Python. A link is represented by the anchor tag. A link can be identified with the help of the locators like - link text and partial link text. We can use the link text attribute for an element for its identification and utilize the method find_element_by_link_text.

Which method is used to browse the URL in WebDriver?

WebDriver interface has a method “navigate()” which returns a type Navigation which is an inner interface in WebDriver interface. Navigation interface is an abstraction allowing the driver to access the browser's history by explicit methods and to navigate to a given URL.


Use current_url element for Python 2:

print browser.current_url

For Python 3 and later versions of selenium:

print(driver.current_url)

According to this documentation (a place full of goodies:)):

driver.current_url

or, see official documentation: https://www.selenium.dev/documentation/en/webdriver/browser_manipulation/#get-current-url


Selenium2Library has get_location():

import Selenium2Library
s = Selenium2Library.Selenium2Library()
url = s.get_location()

Another way to do it would be to inspect the url bar in chrome to find the id of the element, have your WebDriver click that element, and then send the keys you use to copy and paste using the keys common function from selenium, and then printing it out or storing it as a variable, etc.