代码示例:
#!/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.daily.weidian.com/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()
其他方法:
find_element_by_name()
find_element_by_css_selector()