1. 程式人生 > 其它 >API操作(二)

API操作(二)

import time as t
from selenium import webdriver
from selenium.webdriver import ActionChains

# qq音樂
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://y.qq.com/")
driver.find_element_by_link_text('登入').click()
# 進入iframe
t.sleep(5)
driver.switch_to.frame('login_frame')
driver.switch_to.frame('ptlogin_iframe')
driver.find_element_by_link_text('帳號密碼登入').click()
t.sleep(5)
driver.quit()

# 百度設定搜尋設定判斷
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
# 點選設定
settings = driver.find_element_by_xpath('//*[@id="s-usersetting-top"]')
actionChains = ActionChains(driver)
actionChains.move_to_element(settings).perform()
# 點選搜尋設定
driver.find_element_by_xpath('//*[@id="s-user-setting-menu"]/div/a[1]').click()
t.sleep(3)
# 是否顯示10條資料
page = driver.find_element_by_name('NR')
assert page.is_selected() == True
t.sleep(3)
driver.quit()
# 右鍵操作
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
so=driver.find_element_by_id('kw')
action=ActionChains(driver)
action.context_click(so).perform()
t.sleep(5)
driver.quit()

# 百度網盤登入,資料夾右鍵;雙擊
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://pan.baidu.com/")
t.sleep(3)
driver.find_element_by_name('userName').send_keys('使用者名稱')
driver.find_element_by_name('password').send_keys('密碼')
driver.find_element_by_xpath('//*[@id="TANGRAM__PSP_4__submit"]').click()
t.sleep(15)
driver.find_element_by_xpath('//*[@id="wpGuideDialog"]/div/div/div[1]/div').click()
A = driver.find_element_by_xpath('//*[@id="layoutMain"]/div[2]/div[3]/div/div/dd[3]/div[2]/div[1]/a')
action = ActionChains(driver)
# 右鍵單擊
action.context_click(A).perform()
# 雙擊
# action.double_click(A).perform()
t.sleep(3)
driver.quit()

# 鍵盤事件
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
so=driver.find_element_by_id('kw')
so.send_keys('hello UI')
so.send_keys(Keys.CONTROL,'a')
t.sleep(3)
so.send_keys(Keys.BACKSPACE)
t.sleep(3)
driver.quit()

# 鍵盤事件
driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.baidu.com/")
so=driver.find_element_by_id('kw')
so.send_keys('hello UI')
# 全選
so.send_keys(Keys.CONTROL,'a')
# 刪除
so.send_keys(Keys.DELETE)
# # 按F12
# so.send_keys(Keys.F12)
t.sleep(3)
driver.quit()