webdriver常用API-元素操作


  • clear:清除文本框内的文字
1 driver.find_element_by_id('kw').clear()
  • send_keys:向文本域或文件上传按钮发送文字内容
1 driver.find_element_by_id('kw').send_keys('webdriver')
  • click:点击按钮
1 driver.find_element_by_id('kw').click()
  • text:获取节点上的文本信息
1 print(driver.find_element_by_id('TANGRAM__PSP_11__error').text)
  • get_attribute(name):获取元素的属性信息
1 driver.find_element_by_id('kw').send_keys('webdriver')
2 print(driver.find_element_by_id('kw').get_attribute('value'))
  • is_displayed:判断是否显示出来
1 print(driver.find_element_by_id('TANGRAM__PSP_11__error').is_displayed())
2 print(driver.find_element_by_id('TANGRAM__PSP_11__error').is_enabled())
3 print(driver.find_element_by_id('TANGRAM__PSP_11__error').is_selected())