Sometimes we need to get some information such as title, current_url and text in automated testing time
* Title get the current page title
* current_url get the current page the URL of
* text obtain text message
code demonstrates:
rom selenium import webdriver from time import sleep driver = webdriver.Chrome() driver.get("https://www.baidu.com") print('Before search================') # Print the current page title title = driver.title Print ( " title: " + title) # Print the current page the URL of now_url = driver.current_url Print ( " the URL of: " + now_url) driver.find_element_by_id("kw").send_keys("selenium") driver.find_element_by_id("su").click() sleep(2) print('After search================') # Print the current page again title title = driver.title Print ( " title: " + title) # Print the current page the URL of now_url = driver.current_url Print ( " the URL of: " + now_url) # Get the number of search results NUM = driver.find_element_by_class_name ( ' nums_text ' ) .text Print ( " Result: " + NUM) driver.quit()