WebDriver中常用方法:
clear() 清除文本
send_keys(*value) 模拟按键输入
click() 单机元素
网站的登陆
from selenium import webdriver from time import * driver = webdriver.Chrome() url = "https://login.huawei.com/login/?redirect=http%3A%2F%2Fw3.huawei.com%2Fnext%2Findexa.html" print('new access %s' %(url)) driver.get(url) driver.find_element_by_id('uid').clear() driver.find_element_by_id('uid').send_keys("c00358145") sleep(3) driver.find_element_by_id('password').clear() driver.find_element_by_id('password').send_keys("&CTT1106648034") driver.find_element_by_class_name('btn').click() sleep(3) driver.quit() 2.WebElement接口常用的方法 submit()方法用于提交表单 from selenium import webdriver from time import * driver = webdriver.Chrome() url = "https://www.baidu.com" print('new access %s' %(url)) driver.get(url) driver.find_element_by_id('kw').clear() driver.find_element_by_id('kw').send_keys("c00358145") sleep(3) driver.find_element_by_id('kw').submit() sleep(3) driver.quit()
定位搜索框通过submit提交搜素框的内容,达到点击搜素按钮的效果,有时候可以同click()函数交换使用
方法:size() 返回元素的尺寸
text() 获取元素的文本
get_attribute(name)获取属性的值
is_displayed() 设置该元素首付用户可见
from selenium import webdriver
from time import *
driver = webdriver.Chrome()
url = "https://www.baidu.com"
print('new access %s' %(url))
driver.get(url)
size = driver.find_element_by_id('kw').size
print('size%s' %size)
text = driver.find_element_by_xpath("//*[@id='u1']/a[1]").text
print('text%s' %text)
attribute = driver.find_element_by_id('kw').get_attribute('type')
print('%s' %attribute)
sleep(3)
driver.quit()
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。