微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python+selenium+PageObject

import time

from selenium import webdriver
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By


class HomePage:
    login_phone = (By.XPATH, '//form/div[1]/div/div/div/div/input')
    login_pwd = (By.XPATH, '//input[@placeholder="请输入密码"]')
    login_bt = (By.XPATH, '//form/div[4]/div/div[1]/div/button')

    def __init__(self, driver: WebDriver):
        self.driver = driver


    def input_phone(self,phone):
        self.driver.find_element(*self.login_phone).send_keys(phone)

    def input_pwd(self,passwd):
        self.driver.find_element(*self.login_pwd).send_keys(passwd)

    def input_bt(self):
        self.driver.find_element(*self.login_bt).click()



class BaoBeiPage:
    ordermang=(By.XPATH, '//*[@id="siderbar"]/div[1]/div/ul/div[3]/li/div/i[1]')
    baobeilist=(By.XPATH, '//a[text()="列表"]')

    def __init__(self, driver: WebDriver):
        self.driver = driver

    def enter_baobeilist(self):
        time.sleep(20)
        self.driver.find_element(*self.Ordermang).click()
        self.driver.find_element(*self.baobeilist).click()

driver=webdriver.Chrome()
page=HomePage(driver)
page.driver.get('http://www.baidu.com')
page.input_phone('11111111111')
page.input_pwd('654321')
page.input_bt()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐