Exercise scenarios: Baidu home page search box
Script is as follows:
# 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_name("wd") print('test pass:element found by name value') except Exception as e: print("Exception found",format(e)) driver.quit()
Summary: name attribute is not all nodes have, so if there are recommended values to locate it and by - id, by_class the same effect.
Reference article: https://blog.csdn.net/u011541946/article/details/68927000