from selenium import webdriver#驱动浏览器
from selenium.webdriver.common.by import By#选择器
from selenium.webdriver.common.keys import Keys#按键
from selenium.webdriver.support.wait import WebDriverWait#等待页面加载完毕
from selenium.webdriver.support import expected_conditions as EC#等待指定标签加载完毕
from selenium.common.exceptions import TimeoutException, NoSuchElementException#知识点:异常处理模块
from selenium.webdriver import ActionChains
import time,random
class qiangpiao(object):
def __init__(self):
self.url='https://kyfw.12306.cn/otn/resources/login.html'
self.driver=webdriver.Chrome()
self.driver.maximize_window()
def get_data(self):
self.driver.get(self.url)
self.driver.find_element(By.XPATH,'//*[@id="J-userName"]').send_keys('账号')
time.sleep(2)
self.driver.find_element(By.XPATH, '//*[@id="J-password"]').send_keys('密码')
time.sleep(2)
self.driver.find_element(By.XPATH, '//*[@id="J-login"]').click()
time.sleep(2)
self.driver.implicitly_wait(10)
div_Size_1=self.driver.find_element(By.XPATH, '//*[@id="nc_1__scale_text"]/span')
div_Size=div_Size_1.size
print(div_Size)#{'height': 34, 'width': 340}
self.driver.implicitly_wait(10)
button=self.driver.find_element(By.XPATH, '//*[@id="nc_1_n1z"]')
button_location=button.location
print(button_location)
self.driver.implicitly_wait(10)
self.action=ActionChains(self.driver)
self.action.click_and_hold(button).perform()
self.action.move_by_offset(569,450)
self.action.release().perform()
time.sleep(2)
if __name__ == '__main__':
q=qiangpiao()
q.get_data()
自动化selenium
于 2024-05-14 16:25:10 首次发布