自动化selenium

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()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值