#查找元素
driver.find_element_by_xpath() #查找元素這個其實是用的最多的
#然后就是點擊事件
#單擊
dj=driver.find_element_by_xpath()
dj.click()
#其實也可以這么寫,但是我 發現有的時候不生效,只能向上面那樣子寫
driver.find_element_by_xpath().click()
#雙擊,雙擊和單擊的方法是不同的,沒有doubleclick()方法
button = self.driver.find_element_by_xpath(button_xpath)
ActionChains(self.driver).double_click(button).perform()
#輸入內容
input=driver.find_element_by_xpath()
input.send_keys("") #里面需要填寫字串,假如是數字型別就得用 str()方法轉型
input.send_keys(str(20))
#睡眠
很多時候因為資料量大,或者其它原因,加載比較慢,這時候就需要用到睡眠
time.sleep(2) #1是睡眠時間,單位秒
#例外
try:
....
except Exception as e:
....
#for回圈 if while回圈
for i in range(1,5):
#會輸出1,2,3,4 從一開始,不寫1默認為0開始
if 條件:
while 條件:
break,continue
#與break和continue結合使用最佳,可以回圈遍歷,這個有的時候是for回圈做不到的,必須要用while回圈才行
#這個得自己去體會,遇到回圈問題可以想一下怎么搞
#然后寫了個登錄的方法
def login(self):
name_input = self.driver.find_element_by_xpath('路徑')
name_input.send_keys("賬號")
pwd_input = self.driver.find_element_by_xpath('路徑')
pwd_input.send_keys("密碼")
vcode_input = self.driver.find_element_by_xpath('路徑')
# input("請輸入驗證碼后按回車:")
vcode_input.send_keys(input("請輸入驗證碼后按回車:"))
submit_button = self.driver.find_element_by_xpath('路徑')
submit_button.click()
time.sleep(6)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/342066.html
標籤:其他
