#coding =utf-8 from Selenium import webdriver import time driver = Webdriver. Chrome () Driver.maximize_window () driver.implicitly_wait (6) driver.get ("https://www.baidu.com") driver.find_element_by_id ("kw"). Send_keys ("Selenium") driver.find_element_by_id ("su"). Click () time.sleep (3) Driver.back () time.sleep (3) Driver.forward () Time.sleep (3) ele_string = Driver.find_element_by_xpath ("//*[@id = ' 1 ']/ H3/a/em "). Text if (ele_string = =" Selenium "): print U" Test succeeded, the result matches the expected result! " "Print (driver.capabilities[' version ')") Driver.find_element_by_xpath ("//*[@id = ' S_tab ']/a[text () = ' News ']"). Click () # On the Search results page, click on the News category Time.sleep (1) print (Driver.current_url) # Current_url method to get the URL of the current page print ( Driver.title) # Title method can get the title of the current page to display the field driver.quit ()
Python+selenium Browser Back forward operation + Get current page title+ get current page URL