1.submit ()
The Submit () method is used to submit the form. You can use the Submit () method to simulate a query after entering a keyword in the search box and pressing ENTER. If you cannot press ENTER to enter the next step, you cannot use the submit () example, Baidu query submission.
1 fromSeleniumImportWebdriver2 3Dr =Webdriver. Firefox ()4Dr.get ("http://www.baidu.com")5 6DR.FIND_ELEMENT_BY_ID ("kw"). Send_keys ("Selenium")7DR.FIND_ELEMENT_BY_ID ("kw"). Submit ()8Dr.close ()
Submit () can be swapped with Click (), but click () is more widely used
2.get_attribute ()
Gets the attribute value of the element
1 fromSeleniumImportWebdriver2 3Dr =Webdriver. Firefox ()4Dr.get ("http://www.baidu.com")5 6ATTR1 = dr.find_element_by_id ("kw"). Get_attribute ("ID")7 Print("attr1 =%s"%attr1)8ATTR2 = dr.find_element_by_id ("kw"). Get_attribute ("name")9 Print("attr2 =%s"%attr2)TenATTR3 = dr.find_element_by_id ("kw"). Get_attribute ("class") One Print("ATTR3 =%s"%ATTR3) AATTR4 = dr.find_element_by_id ("kw"). Get_attribute ("value") - Print("ATTR4 =%s"%ATTR4) -Dr.close ()
Python+selenium Study Notes 4