1.submit()
submit()方法用于提交表单。如在搜索框输入关键字后按回车键进行查询操作,就可用submit()方法模拟。若不能按回车键进入下一步,则不能用submit()举例,百度的查询提交。
1 from selenium import webdriver 2 3 dr = webdriver.Firefox() 4 dr.get("http://www.baidu.com") 5 6 dr.find_element_by_id("kw").send_keys("selenium") 7 dr.find_element_by_id("kw").submit() 8 dr.close()
submit()可与click()互换,但click()的应用范围更广泛
2.get_attribute()
获取元素的属性值
1 from selenium import webdriver 2 3 dr = webdriver.Firefox() 4 dr.get("http://www.baidu.com") 5 6 attr1 = dr.find_element_by_id("kw").get_attribute("id") 7 print("attr1 = %s" % attr1) 8 attr2 = dr.find_element_by_id("kw").get_attribute("name") 9 print("attr2 = %s" % attr2) 10 attr3 = dr.find_element_by_id("kw").get_attribute("class") 11 print("attr3 = %s" % attr3) 12 attr4 = dr.find_element_by_id("kw").get_attribute("value") 13 print("attr4 = %s" % attr4) 14 dr.close()
原文地址:https://www.cnblogs.com/sue2015/p/9038592.html
时间: 2024-10-11 20:10:52