Python调用selenium

时间:2021-03-24 16:39:10
import time
from selenium import webdriver
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains mobile = {'deviceName': 'iPhone 6'}
path='E:\\chromedriver\\chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation',mobile)
driver = webdriver.Chrome(path,chrome_options=options)
driver.set_window_size(375,667)
driver.get('https://api.8***')
##driver.find_element_by_css_selector('#index-kw').send_keys('test')
##el = driver.find_element_by_id("index-bn")
##TouchActions(driver).tap(el).perform() driver.switch_to_frame(0)
time.sleep(3) ##driver.find_element_by_id("msgBtn").click() el = driver.find_element_by_id("msgBtn")
ActionChains(driver).move_to_element(el).perform()
#time.sleep(3)
#ActionChains(driver).move_by_offset(10, 50).perform()
##TouchActions(driver).tap(el).perform()
#time.sleep(3) #ActionChains(driver).move_to_element(el).click(el).perform()
TouchActions(driver).tap(el).perform() #time.sleep(3)
msgCode = driver.find_element_by_id('msgCode')
driver.find_element_by_id("msgCode").send_keys("1")
time.sleep(3)
driver.find_element_by_id("msgCode").send_keys("2")
time.sleep(3)
driver.find_element_by_id("msgCode").send_keys("3")
time.sleep(3)
driver.find_element_by_id("msgCode").send_keys("4")
time.sleep(3)
driver.find_element_by_id("msgCode").send_keys("5")
time.sleep(3)
driver.find_element_by_id("msgCode").send_keys("5") e2 = driver.find_element_by_id("okPay")
ActionChains(driver).move_to_element(e2).perform()
time.sleep(3)
TouchActions(driver).tap(e2).perform()
##TouchActions(driver).