代码示例:css
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# coding:utf8
import sys
import os
from selenium import webdriver
sys.path.append(os.getcwd())
driver = webdriver.Chrome('/Users/fyh/tool/chromedriver') # Optional argument, if not specified will search path.
#注意此处的chromedriver须要与浏览器的版本匹配,不然会报错
# options=webdriver.ChromeOptions()
# options.add_argument('disable-infobars')
driver.set_page_load_timeout(30)
driver.implicitly_wait(30)
#登陆
driver.get("https://h5./m/zhaoshang-h5/apply.html?id=30898")#打开连接
driver.find_element_by_id("J_phone").send_keys("13876543566")#找到控件并发送文字
driver.find_element_by_id("J_password").send_keys("123456")
driver.find_element_by_id("J_submit").click()#找到控件并点击按钮
driver.find_elements_by_class_name("common_button")[0].click()#经过find_elements_by_class_name找控件
text=driver.find_element_by_xpath("//*[@id=\"app\"]/div/div/div/section[1]/div[1]/span").text#经过find_element_by_xpath找控件
if text == "未经过":
print("经过")
else:
print("不经过")
sleep(2)
driver.quit()
其余方法:html
find_element_by_name()
find_element_by_css_selector()
如果觉得《pythonwebui自动化_python+selenium实现web端UI自动化测试》对你有帮助,请点赞、收藏,并留下你的观点哦!