browser.find_element_by_id("id的name")
browser.find_element("")
browser.find_element_by_tag_name("标签name")
browser.find_element_by_class_name("classname")
browser.find_element_by_css_selector("css选择器,cssname")
browser.find_element_by_partial_link_text("带有链接的文本,获取其跳转地址,后面跟click事件可以模拟跳转")

from selenium import webdriver
obj = webdriver.PhantomJS(executable_path="D:\Python27\Scripts\phantomjs.exe")
obj.set_page_load_timeout(5)
try:
obj.get('http://www.baidu.com')
print obj.find_element_by_id("cp").text # 获取元素的文本信息
obj.find_element_by_id('kw').clear() #用于清除输入框的内容
obj.find_element_by_id('kw').send_keys('Hello') #在输入框内输入Hello
obj.find_element_by_id('su').click() #用于点击按钮
obj.find_element_by_id('su').submit() #用于提交表单内容

except Exception as e:
print e

browser.find_element_by_xpath("里面可以跟正则表达式,XPath一般在实际自动化测试项目中用到比较多,其定位元素十分方便")

相关文章:

  • 2022-12-23
  • 2021-06-20
  • 2021-12-28
  • 2022-01-01
  • 2021-07-23
  • 2021-08-13
  • 2021-07-24
  • 2021-11-29
猜你喜欢
  • 2021-10-26
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案