Selenium的Python模塊旨在通過Python執行自動測試。 Selenium Python綁定提供了一個簡單的API,可以使用Selenium WebDriver編寫函數/驗收測試。要使用Selenium Python打開網頁,請簽出-使用get方法導航鏈接-Selenium Python。能夠去某個地方並不是很有用。我們真正想要做的是與頁麵(或更具體地說,頁麵內的HTML元素)進行交互。使用硒,結帳-定位策略有多種策略來查找元素。 Selenium WebDriver提供了各種有用的方法來控製會話,即瀏覽器。例如,添加cookie,按返回按鈕,在選項卡之間導航等。
本文圍繞current_url
Selenium中的驅動程序方法。current_url
方法獲取當前頁麵的當前URL。
句法 -
driver.current_url
範例-
現在可以使用current_url方法作為驅動程序,如下所示-
diver.get("https://www.geeksforgeeks.org/")
driver.current_url
如何在Selenium Python中使用current_url驅動程序方法?
展示,current_url
Selenium Python中WebDriver的方法。讓我們訪問https://www.geeksforgeeks.org/並對驅動程序對象進行操作。讓我們得到current_url,
程序 -
# import webdriver
from selenium import webdriver
# create webdriver object
driver = webdriver.Firefox()
# get geeksforgeeks.org
driver.get("https://www.geeksforgeeks.org/")
# get current url
print(driver.current_url)
輸出-
屏幕截圖已添加-
終端輸出-
相關用法
- Selenium Python find_element_by_name()用法及代碼示例
- Selenium Python find_element_by_xpath()用法及代碼示例
- Selenium Python find_element_by_link_text()用法及代碼示例
- Selenium Python find_element_by_partial_link_text()用法及代碼示例
- Selenium Python find_element_by_tag_name()用法及代碼示例
- Selenium Python find_element_by_class_name()用法及代碼示例
- Selenium Python find_element_by_id()用法及代碼示例
- Selenium Python find_element_by_css_selector()用法及代碼示例
- Selenium Python find_elements_by_name()用法及代碼示例
- Selenium Python find_elements_by_xpath()用法及代碼示例
- Selenium Python find_elements_by_link_text()用法及代碼示例
- Selenium Python find_elements_by_partial_link_text()用法及代碼示例
- Selenium Python find_elements_by_tag_name()用法及代碼示例
- Selenium Python find_elements_by_class_name()用法及代碼示例
- Selenium Python find_elements_by_css_selector()用法及代碼示例
- Selenium Python add_cookie用法及代碼示例
- Selenium Python fullscreen_window用法及代碼示例
- Selenium Python execute_script用法及代碼示例
- Selenium Python execute_async_script用法及代碼示例
- Selenium Python get_cookies用法及代碼示例
- Selenium Python close用法及代碼示例
- Selenium Python create_web_element用法及代碼示例
- Selenium Python delete_all_cookies用法及代碼示例
注:本文由純淨天空篩選整理自NaveenArora大神的英文原創作品 current_url driver method – Selenium Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。