Exercise Python + Selenium (b) - Use ID targeting elements

Exercise Scene: to locate the information element by element node ID, Example: id Baidu Home Location search input box.

# coding=utf-8

from selenium import webdriver

driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(6)

driver.get("https://www.baidu.com")
try:
    driver.find_element_by_id("kw")
    print('test pass : ID found')
except Exception as e:
    print("Exception found",format(e))

driver.quit()

  

To test assertions by fine try except statement that the actual automated test script development, often use to handle exceptions.

 

Reference article: https://blog.csdn.net/u011541946/article/details/68489278

Guess you like

Origin www.cnblogs.com/zhaocbbb/p/12617407.html